Skip to content

Instantly share code, notes, and snippets.

View heydona's full-sized avatar

Andy Heydon heydona

View GitHub Profile
@heydona
heydona / gist:4719780
Created February 6, 2013 02:41
UIScrollView infinite scroll for dates
@interface MealPlanScrollView () {
NSMutableArray *_dayViews;
NSInteger _numberOfDays;
NSInteger _viewFirstDateNum;
NSInteger _viewLastDateNum;
NSInteger _todayDateNum;
NSInteger _maxNumberOfDays;
}
@heydona
heydona / gist:4569311
Last active December 11, 2015 07:49
Canceling a delete confirmation
- (void)willTransitionToState:(UITableViewCellStateMask)state {
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
// ...
_showingConfirmation = YES;
_cancelDeleteGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deleteConfirmation:)];
[_table addGestureRecognizer:_cancelDeleteGesture];
@heydona
heydona / gist:4569151
Created January 18, 2013 22:19
Delete confirmation
- (void)delete:(id)sender {
_isDeleting = YES;
[self commitEdit:UITableViewCellEditingStyleDelete];
}
- (void)commitEdit:(UITableViewCellEditingStyle)editStyle {
[self willTransitionToState:UITableViewCellStateShowingEditControlMask];
if ([[_table dataSource] respondsToSelector:@selector(tableView:commitEditingStyle:forRowAtIndexPath:)]) {
@heydona
heydona / gist:4568981
Last active December 11, 2015 07:49
Adding a new delete confirmation button
- (void)willTransitionToState:(UITableViewCellStateMask)state {
CGRect f;
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
if (!_deleteButton) {
_deleteButton = [MPButton buttonWithType:MPButtonTypeAlert withTitle:NSLocalizedString(@"Delete",@"Delete")];
[[_deleteButton titleLabel] setFont:[[UIFont buttonFont] changeFontSizeBy:-2]];
[_deleteButton addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
@heydona
heydona / gist:4568814
Last active December 11, 2015 07:48
Basic willTransitionToState:
- (void)willTransitionToState:(UITableViewCellStateMask)state {
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
} else {
[super willTransitionToState:state];
}
}
@heydona
heydona / gist:4347489
Created December 20, 2012 18:26
Containers need to consult child view controllers about rotation events
- (BOOL)shouldAutorotate {
BOOL autoRotate = YES;
for (UIViewController *vc in [self childViewControllers]) {
autoRotate = autoRotate && [vc shouldAutorotate];
}
return autoRotate;
}
- (NSUInteger)supportedInterfaceOrientations {
NSUInteger supported = IPAD ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskAllButUpsideDown;
@heydona
heydona / gist:4347450
Created December 20, 2012 18:20
UINavigationController to consult top view controller about rotation
@implementation UINavigationController (Rotation)
// iOS 6
- (BOOL)shouldAutorotate {
return [[self topViewController] shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [[self topViewController] supportedInterfaceOrientations];
@heydona
heydona / gist:4347302
Created December 20, 2012 18:02
Support only portrait rotation for iPhone
- (BOOL)shouldAutorotate {
return IPAD ? YES : NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return IPAD ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskPortrait;
}
@heydona
heydona / gist:4262110
Created December 11, 2012 21:01
Implement properties using associated objects
@implementation UIViewController (RBPopoverPrivate)
- (UIPopoverController *)hiddenPopoverController {
return objc_getAssociatedObject(self, HiddenPopoverControllerKey);
}
- (void)setHiddenPopoverController:(UIPopoverController *)hiddenPopoverController {
objc_setAssociatedObject(self, HiddenPopoverControllerKey, hiddenPopoverController, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@heydona
heydona / gist:4261964
Created December 11, 2012 20:42
Private category properties and associated object keys
static char const * const HiddenPopoverControllerKey = "HiddenPopoverController";
static char const * const HiddenPopoverContentKey = "HiddenPopoverContent";
static char const * const HiddenPopoverDelegateKey = "HiddenPopoverDelegate";
static char const * const HiddenPopoverPresentingRectKey = "HiddenPopoverPresentingRect";
static char const * const HiddenPopoverPresentingButtonKey = "HiddenPopoverPresentingButton";
static char const * const HiddenPopoverArrowDirectionKey = "HiddenPopoverArrowDirection";
static char const * const HiddenPopoverAnimatedKey = "HiddenPopoverAnimated";
static char const * const HiddenPopoverContentSizeKey = "HiddenPopoverContentSize";
static char const * const HiddenPopoverHidingInProgessKey = "HiddenPopoverHidingInProgress";