Tag: objective c

Is it necessary to assign a string to a variable before comparing it to another?

I want to compare the value of an NSString to the string “Wrong”. Here is my code: NSString *wrongTxt = [[NSString alloc] initWithFormat:@”Wrong”]; if( [statusString isEqualToString:wrongTxt] ){ doSomething; } Do I really have to create an NSString for “Wrong”? Also, can I compare the value of a UILabel‘s text to a string without assigning the […]

ios8 iPad uiwebview crashes while displaying popover when user taps drop down list HTML select tag

On ios8 and iPad if a uiwebview is displaying a HTML page containing a drop down list eg this page http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select then repeatedly tap on the HTML drop down list that contain lists of cars . first item is Volvo. tap every 1/2 second or so that uipopover opens and closes app will crash: Terminating […]

UITabBar not showing selected item images in ios 7

The icons show fine in ios 6 but not in ios 7. I’m setting the selected state in the viewController viewDidLoad method. When the user selects a tab bar item the image disappears. Here is my code: UITabBar *tabBar = self.tabBarController.tabBar; if ([UITabBar instancesRespondToSelector:@selector(setSelectedImageTintColor:)]) { [self.tabBarController.tabBar setSelectedImageTintColor:[UIColor whiteColor]]; } UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; UITabBarItem […]

Dark shadow on navigation bar during segue transition after upgrading to Xcode 5.1 and iOS 7.1

When I am navigating back & forth between parent and child controllers in a master – detail navigation controller, i see a dark shadow on the right side of navigation bar at top. It started after I upgraded to Xcode 5.1. It feels rough and distracting. How can I get rid of it?

UIBezierPath Subtract Path

By using [UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:], I am able to create a rounded view, such as this: How could I subtract another path from this one (or some other way), to create a path like this: Is there any way I can do something like this? Pseudocode: UIBezierPath *bigMaskPath = [UIBezierPath bezierPathWithRoundedRect:bigView.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(18, 18)]; UIBezierPath *smallMaskPath […]

iPhone: Setting Navigation Bar Title

Hey all. I’m still pretty new to iPhone development, and I’m having a bit of trouble figuring out how to change the title of my Navigation Bar. On another question on this site somebody recommended using : viewController.title = @”title text”; but that isn’t working for me…Do I need to add a UINavigationController to accomplish […]

How to decode the Google Directions API polylines field into lat long points in objective-C for iPhone?

I want to draw routes on a map corresponding to directions JSON which I am getting through the Google Directions API: http://code.google.com/apis/maps/documentation/directions/ I have figured out how to extract the latitude and longitude from the steps field, however this doesn’t follow curvy roads very well. I think what I need is to decode the polyline […]

Getting the visible rect of an UIScrollView's content

How can I go about finding out the rect (CGRect) of the content of a displayed view that is actually visible on screen. myScrollView.bounds The code above works when there’s no zooming, but as soon as you allow zooming, it breaks at zoom scales other than 1. To clarify, I want a CGRect that contains […]

Why does NSError need double indirection? (pointer to a pointer)

This concept seems to trouble me. Why does an NSError object need its pointer passed to a method that is modifying the object? For instance, wouldn’t just passing a reference to the error do the same thing? NSError *anError; [myObjc doStuff:withAnotherObj error:error]; and then in doStuff: – (void)doStuff:(id)withAnotherObjc error:(NSError *)error { // something went bad! […]

Suppress warning “Category is implementing a method which will also be implemented by its primary class”

I was wondering how to suppress the warning: Category is implementing a method which will also be implemented by its primary class. I have this for a specific code category: + (UIFont *)systemFontOfSize:(CGFloat)fontSize { return [self aCustomFontOfSize:fontSize]; }