View TableViewController.m
pageNumber = 1;
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSInteger currentOffset = scrollView.contentOffset.y;
NSInteger maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height;
if (maximumOffset - currentOffset <= - 40 && hasNextPage)
{
[self fetchData];
View SortArray.m
// 'date' is the property with the date to be sorted by
NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
// 'myArray' is the array that will be sorted
NSArray *sortedEventArray = [myArray sortedArrayUsingDescriptors:sortDescriptors];
View TableViewController.m
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
View TableViewController.m
// selectedRow is the row to update
NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:selectedRow inSection:0];
NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
[tableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];
View TableViewController.m
NSInteger selectedRow = -1; // default selected row (here no one)
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == selectedRow) {
return 100; // expanded height
}
return 44; // colapsed height
}
View ImageScaled.m
-(UIImage *)scaleImage:(UIImage *)image toWidth:(int)width {
// determine the scaling factor to fit the screen width
CGFloat oldWidth = image.size.width;
NSUInteger newWidth = (width - 10);
CGFloat scaleFactor;
if (oldWidth > newWidth)
scaleFactor = oldWidth / newWidth;
else
View Info.plist
View controller-based status bar appearance = NO
Status bar style = UIStatusBarStyleLightContent
View RegexExample.swift
let text = "Text to get the match"
let regex = NSRegularExpression(pattern: "([^ ]+)", options: nil, error: nil)!
let matches = regex.matchesInString(text, options: nil, range: NSRange(location: 0, length: count(text)))
var substring = ""
for match in matches as! [NSTextCheckingResult] {
// range at index 0 returns the full match
// range at index 1 returns the first capture group
// range at index 2 returns the second capture group and so on...
View ViewController.swift
navigationController?.popViewControllerAnimated(true)
View TableViewController.swift
// first enable "Refreshing" on controller via storyboard
override func viewDidLoad() {
super.viewDidLoad()
// the value for "action" must mach the function's name
refreshControl?.addTarget(self, action: "reloadStuff", forControlEvents: UIControlEvents.ValueChanged)
}
func reloadStuff() {