Skip to content

Instantly share code, notes, and snippets.

View mikeabdullah's full-sized avatar

Mike Abdullah mikeabdullah

View GitHub Profile
extern NSArray *PRHArrayByMap(NSArray *inArray, id (^block)(id));
@mikeabdullah
mikeabdullah / gist:31cdf36f5e60a36b2d80
Created June 18, 2014 15:33
Passing along toolbar items during a segue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIViewController *destination = segue.destinationViewController;
destination.toolbarItems = self.toolbarItems;
}
@mikeabdullah
mikeabdullah / gist:16515456ed26cddb8122
Created June 18, 2014 19:03
Grabbing toolbar items from the navigation controller
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.toolbarItems = self.navigationController.toolbarItems;
}
@mikeabdullah
mikeabdullah / gist:37bc493db7686fac5764
Created June 20, 2014 14:59
Loading toolbar items for editing mode from storyboard
- (void)viewDidLoad {
[super viewDidLoad];
_stashedToolbarItemsForEditingMode = self.toolbarItems;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if (editing) {
self.toolbarItems = _stashedToolbarItemsForEditingMode;
@mikeabdullah
mikeabdullah / gist:dbdaeef1db48551265a4
Created June 20, 2014 15:20
Detecting if in editing mode, or just editing a single table row
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
_isEditingIndividualRow = YES;
[super tableView:tableView willBeginEditingRowAtIndexPath:indexPath];
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
BOOL inEditingMode = editing && !_isEditingIndividualRow;
if (inEditingMode) // ...set up toolbar accordingly
@mikeabdullah
mikeabdullah / gist:62c0acc03f9d6d19e959
Last active August 29, 2015 14:02
Switching on allowsMultipleSelectionDuringEditing as needed
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if (!_isEditingIndividualRow) {
self.tableView.allowsMultipleSelectionDuringEditing = editing;
}
}
@mikeabdullah
mikeabdullah / gist:c6f5569da6b38b995e9d
Created June 23, 2014 11:32
NSFetchedResultsController stress test config to repro sectioning bug
// Initial Configuration
#define NUMBER_INITIAL_OBJECTS 0
#define USE_PREDICATE 1
#define SPLIT_INTO_SECTIONS 1
// Things to try changing in the model
#define INSERT_OBJECTS 1
#define MAX_INSERTIONS 2
#define DELETE_OBJECTS 1
#define EDIT_INTERVAL 0.5
@mikeabdullah
mikeabdullah / gist:939faf318d1b8362fae4
Created June 23, 2014 11:48
Treating NSFetchedResultsSectionInfo.numberOfObjects as the truth
- (void)trueObjectsInSection:(id <NSFetchedResultsSectionInfo>)section {
NSArray *objects = section.objects;
NSUInteger number = section.numberOfObjects;
if (number > objects.count) {
objects = [objects subArrayWithRange:NSMakeRange(0,number)];
}
return objects;
}
@mikeabdullah
mikeabdullah / gist:1098b19db126922dd2ff
Created June 23, 2014 11:53
Apple's default implementation for numberOfRowsInSection
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];
return [sectionInfo numberOfObjects];
}
@mikeabdullah
mikeabdullah / gist:83170260dfbc5e3e890f
Created June 26, 2014 11:20
Detecting if in editing mode, or just editing a single table row alternative
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
[super setEditing:YES animated:YES];
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
// Adjust toolbar etc. acordingly
}