Skip to content

Instantly share code, notes, and snippets.

View mikeabdullah's full-sized avatar

Mike Abdullah mikeabdullah

View GitHub Profile
@mikeabdullah
mikeabdullah / MyTableViewCell.m
Created November 26, 2014 09:23
Connecting cell to controller by responder chain
@implementation MyTableViewCell
- (IBAction)checkboxPressed:(UIButton *)checkbox event:(UIEvent *)event {
// Send onwards up the responder chain with the cell as sender
[UIApplication.sharedApplication sendAction:@selector(cellCheckboxPressed:)
to:nil
from:self
event:event];
}
@mikeabdullah
mikeabdullah / MyTableViewCell.h
Created November 26, 2014 09:12
Connecting cell to controller by delegation
@protocol MyTableViewCellDelegate
- (void)tableCellCheckboxPressed:(MyTableViewCell *)cell;
@end
@mikeabdullah
mikeabdullah / MyTableViewCell.m
Created November 26, 2014 09:04
Connecting button's action via the cell
@implementation MyTableViewCell
- (IBAction)checkboxPressed:(UIButton *)checkbox {
// Dispatch onwards to controller with extra info
// so it can easily identify which task/cell/row
// is being acted on.
}
@end
@mikeabdullah
mikeabdullah / MyTableViewController.m
Created November 26, 2014 08:59
Connecting in-cell button direct to view controller
@implementation MyTableViewController
- (IBAction)checkboxPressed:(UIButton *)button {
// Figure out which row this checkbox belongs to
id aView = button.superview;
while (![aView isKindOfClass:UITableViewCell.class]) {
aView = [aView superview];
}
NSIndexPath *row = [self.tableView indexPathForCell:aView];
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
BOOL inMultipleSelectionMode = (self.tableView.editing ?
self.tableView.allowsMultipleSelectionDuringEditing :
self.tableView.allowsMultipleSelection);
NSIndexPath *selectedRowIndexPath = [self.tableView indexPathForSelectedRow];
if (selectedRowIndexPath && !inMultipleSelectionMode) {
@mikeabdullah
mikeabdullah / gist:bdd5e30ad856fa79ee87
Created November 21, 2014 19:10
Querying if root view controller is being dismissed
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
UIViewController *root = self.presentingViewController.presentedViewController;
if (root.isBeingDismissed) {
[self.view endEditing:YES];
}
}
@mikeabdullah
mikeabdullah / gist:6d6c3f3874fb55995b11
Created November 21, 2014 19:07
Attempt to end editing during dismissal
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (self.isBeingDismissed) {
[self.view endEditing:YES];
}
}
@mikeabdullah
mikeabdullah / gist:77e4213df543f6bd867d
Created November 19, 2014 18:53
Manually triggering layout after setting cell's detail text
cell.detailTextLabel.text = updatedText;
[cell setNeedsLayout];
@mikeabdullah
mikeabdullah / gist:28e55849f335a46560b4
Created November 13, 2014 17:15
Configuring presentation with custom modal segue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
MyViewController *destination = segue.destinationViewController;
// Configure view controller
}
@mikeabdullah
mikeabdullah / gist:bca589d2454949307620
Created November 13, 2014 17:12
Typical modal segue preparation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UINavigationController *navController = segue.destinationViewController;
MyViewController *realDestination = navController.viewControllers[0];
// Configure view controller
}