UITableView with two custom cells (multiple identifiers)

* I’ve renamed some of your NIB/Class names for a better understanding. * First, you should register each cells’ NIB: – (void)viewDidLoad{ [super viewDidLoad]; static NSString *CellIdentifier1 = @”ContentCell”; static NSString *CellIdentifier2 = @”SpaceCell”; UINib *nib = [UINib nibWithNibName:@”CellViewNIBName” bundle:nil]; [self.tableView registerNib:nib forCellReuseIdentifier:CellIdentifier1]; nib = [UINib nibWithNibName:@”CellSpaceNIBName” bundle:nil]; [self.tableView registerNib:nib forCellReuseIdentifier:CellIdentifier2]; self.contentView.hidden = YES; [self … Read more

How to get the width of an NSString?

Here’s a relatively simple approach. Just create an NSAttributedString with the appropriate font and ask for its size: – (CGFloat)widthOfString:(NSString *)string withFont:(NSFont *)font { NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]; return [[[NSAttributedString alloc] initWithString:string attributes:attributes] size].width; }

Give warning when [super method] is not called

Recent versions of llvm have added an attribute that indicates that subclasses must call super: @interface Barn:NSObject – (void)openDoor NS_REQUIRES_SUPER; @end @implementation Barn – (void) openDoor { ; } @end @interface HorseBarn:Barn @end @implementation HorseBarn – (void) openDoor { ; } @end Compiling the above produces the warning: Method possibly missing a [super openDoor] call

Adding Images to UIActionSheet buttons as in UIDocumentInteractionController

There is a possibility to add images (to be exact: icons or symbols) to the buttons of a UIActionSheet (or a UIAlertView) without loading image files or fiddling around with (sub)views. In these classes buttons are specified by their titles, which are strings. So it is obvious to use symbols, which one can specify also … Read more

UIScrollview with UIButtons – how to recreate springboard?

Solution that worked for me included: Setting canCancelContentTouches in UIScrollView to YES. Extending UIScrollView to override touchesShouldCancelInContentView:(UIView *)view to return YES when view is a UIButton. According to documentation touchesShouldCancelInContentView returns “YES to cancel further touch messages to view, NO to have view continue to receive those messages. The default returned value is YES if … Read more

Getting username and profile picture from Facebook iOS 7

This is the simplest way I’ve found to get the user’s profile picture. [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) { if (error) { // Handle error } else { NSString *userName = [FBuser name]; NSString *userImageURL = [NSString stringWithFormat:@”https://graph.facebook.com/%@/picture?type=large”, [FBuser objectID]]; } }]; Other query parameters that can be used are: type: small, … Read more

table header view height is wrong when using auto layout, IB, and font sizes

Note: A Swift 3+ version can be found here: https://gist.github.com/marcoarment/1105553afba6b4900c10#gistcomment-1933639 The idea is to calculate header’s height with help of systemLayoutSizeFittingSize:targetSize. Returns the size of the view that satisfies the constraints it holds. Determines the best size of the view considering all constraints it holds and those of its subviews. After changing header’s height it … Read more

How does Apple update the Airport menu while it is open? (How to change NSMenu when it is already open)

Menu mouse tracking is done in a special run loop mode (NSEventTrackingRunLoopMode). In order to modify the menu, you need to dispatch a message so that it will be processed in the event tracking mode. The easiest way to do this is to use this method of NSRunLoop: [[NSRunLoop currentRunLoop] performSelector:@selector(updateTheMenu:) target:self argument:yourMenu order:0 modes:[NSArray … Read more