Is it possible to NOT dismiss a UIAlertView

Yes. Subclass UIAlertView and then overload -dismissWithClickedButtonIndex:animated:, e.g. @implementation MyAlertView -(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { if (buttonIndex should not dismiss the alert) return; [super dismissWithClickedButtonIndex:buttonIndex animated:animated]; } @end Unofficially you can define a -(void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(id)button; method to the delegate which will make it bypass -dismissWithClickedButtonIndex:animated:, but it’s undocumented, so I don’t know whether it’s suitable for you.

Add lefthand margin to UITextField

You can do it by extending UITextField class and overriding two methods: – (CGRect)textRectForBounds:(CGRect)bounds; – (CGRect)editingRectForBounds:(CGRect)bounds; Here is the code: The interface in MYTextField.h @interface MYTextField : UITextField @end Its implementation in MYTextField.m @implementation MYTextField static CGFloat leftMargin = 28; – (CGRect)textRectForBounds:(CGRect)bounds { bounds.origin.x += leftMargin; return bounds; } – (CGRect)editingRectForBounds:(CGRect)bounds { bounds.origin.x += leftMargin; … Read more

Sorting NSString values as if NSInteger using NSSortDescriptor

You can do this by implementing a custom comparator block when creating your NSSortDescriptor: NSSortDescriptor *aSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@”sort” ascending:YES comparator:^(id obj1, id obj2) { if ([obj1 integerValue] > [obj2 integerValue]) { return (NSComparisonResult)NSOrderedDescending; } if ([obj1 integerValue] < [obj2 integerValue]) { return (NSComparisonResult)NSOrderedAscending; } return (NSComparisonResult)NSOrderedSame; }]; self.myList = [NSMutableArray arrayWithArray:[unsortedList sortedArrayUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]]]; See … Read more

How to figure out the font size of a UILabel when -adjustsFontSizeToFitWidth is set to YES?

I’m not sure if this is entirely accurate, but it should be pretty close, hopefully. It may not take truncated strings into account, or the height of the label, but that’s something you might be able to do manually. The method – (CGSize)sizeWithFont:(UIFont *)font minFontSize:(CGFloat)minFontSize actualFontSize:(CGFloat *)actualFontSize forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode will return the text size, and … Read more

iOS7 iPad Landscape only app, using UIImagePickerController

If your iPad app is landscape only in all conditions, just do these 3 steps : 1) In your app delegate – (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskAll; } 2) Create a category header #import “UIViewController+OrientationFix.h” @implementation UIViewController (OrientationFix) – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return UIInterfaceOrientationIsLandscape(toInterfaceOrientation); } – (BOOL)shouldAutorotate { return YES; } – (NSUInteger)supportedInterfaceOrientations { … Read more

Moving a CLLocation by x meters

A conversion to Swift, taken from this answer: func locationWithBearing(bearingRadians:Double, distanceMeters:Double, origin:CLLocationCoordinate2D) -> CLLocationCoordinate2D { let distRadians = distanceMeters / (6372797.6) // earth radius in meters let lat1 = origin.latitude * M_PI / 180 let lon1 = origin.longitude * M_PI / 180 let lat2 = asin(sin(lat1) * cos(distRadians) + cos(lat1) * sin(distRadians) * cos(bearingRadians)) let … Read more

Send a file as attachment in objective c

Use the method below -(void)displayComposerSheet { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setSubject:@”Check out this image!”]; // Set up recipients // NSArray *toRecipients = [NSArray arrayWithObject:@”first@example.com”]; // NSArray *ccRecipients = [NSArray arrayWithObjects:@”second@example.com”, @”third@example.com”, nil]; // NSArray *bccRecipients = [NSArray arrayWithObject:@”fourth@example.com”]; // [picker setToRecipients:toRecipients]; // [picker setCcRecipients:ccRecipients]; // [picker setBccRecipients:bccRecipients]; // Attach … Read more

Attempt to present * on * whose view is not in the window hierarchy

You can’t display a modal view controller from the appDelegate. You need to display a modal ViewController from whichever viewController is currently displaying full-screen. In other words, you need to put that code into your root view controller, or whichever one you want to display the modal vc from… Also, you’ll want to use the … Read more

Changing font size of tabbaritem

I recommend a better way: [yourTabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], UITextAttributeTextColor, [NSValue valueWithUIOffset:UIOffsetMake(0,0)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@”Helvetica” size:18.0], UITextAttributeFont, nil] forState:UIControlStateNormal];