Uploaded October 2012 | Updated September 2026, 2 weeks ago
Subscribe to our channel here for notifications on new video trainings. For more videos on technology, visit our website at http://www.techytube.com.
By pavel@techytube, for more from this author visit:
techytube.com/author/pavel
When we programming in Objective-C, there are situations when some unexpected things may appear. For example, an object might get a type when it should be of a totally different type. And when we try to call some methods on that object, we get our program crashed, with an "unrecognised selector send to that specific object" exception.
To deal around that, we should use the @try {} @catch {} @finally {} block. All the modern object oriented programming language have such syntax, and there are many situations where we can make use of it.
Basically, inside the @try section, we insert our code that generated the exception(s). Than if one appear, we have to handle that in the @catch block. @catch has a NSException object as a parameter, and we can use it to check different things (what exactly is the type of exception, where it came from etc.). @finally is executed wether am exception was raised or not. As a more practical example, say we are working with a Database, and we have a connection opened with the DB, and after we successfully executed some queries to the DB, when trying to manipulate the result - our program crashed. We can use the @try {} @catch {} @finally {} block in this case. In @try section we'll do all the heavy work. If an @catch section we log something to the Console, or give some alert to the user in case of a Graphical User Interface. But the connection is still opened :(. And the solution is to fix that in the finally block :). If it's opened, close it, and also release the other allocated resources.
Subscribe to our channel here for notifications on new video trainings. For more videos on technology, visit our website at http://www.techytube.com.
By pavel@techytube, for more from this author visit:
techytube.com/author/pavel
When we programming in Objective-C, there are situations when some unexpected things may appear. For example, an object might get a type when it should be of a totally different type. And when we try to call some methods on that object, we get our program crashed, with an "unrecognised selector send to that specific object" exception.
To deal around that, we should use the @try {} @catch {} @finally {} block. All the modern object oriented programming language have such syntax, and there are many situations where we can make use of it.
Basically, inside the @try section, we insert our code that generated the exception(s). Than if one appear, we have to handle that in the @catch block. @catch has a NSException object as a parameter, and we can use it to check different things (what exactly is the type of exception, where it came from etc.). @finally is executed wether am exception was raised or not. As a more practical example, say we are working with a Database, and we have a connection opened with the DB, and after we successfully executed some queries to the DB, when trying to manipulate the result - our program crashed. We can use the @try {} @catch {} @finally {} block in this case. In @try section we'll do all the heavy work. If an @catch section we log something to the Console, or give some alert to the user in case of a Graphical User Interface. But the connection is still opened :(. And the solution is to fix that in the finally block :). If it's opened, close it, and also release the other allocated resources.
![How to customize the NavBar in iOS
Subscribe to our channel here for notifications on new video trainings. For more videos on technology, visit our website at http://www.techytube.com.
By pavel@techytube, for more from this author visit:
http://www.techytube.com/author/pavel
The NavBar or the navigation bar is the top side view that appears by default over our main view if we have a navigation controller presenting the corresponding view controller.
Its dimensions for iPhone and iPod touch are 320 x 44, so if we want to set custom background images for that, we need 2 images: one normal of 320 x 44 pixels, and the other one for Retina Display, of 640 x 88 pixels.
iOS provides us 4 default options for customising the NavBar, and we do that by writing the following line of code:
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
The barStyle property can be set to one of 4 values, which are:
UIBarStyleDefault,
UIBarStyleBlack,
UIBarStyleBlackOpaque,
UIBarStyleBlackTranslucent.
Starting with iOS 5, it is very easy to set a background image for the NavBar in this way:
UIImage *navBarImage = [UIImage imageNamed:@nav-bar-image];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault]; How to customize the NavBar in iOS](https://i.ytimg.com/vi/kjQ4qVGHr9w/mqdefault.jpg)









