Wednesday, 29 February 2012

iPhone Development Tutorials for Beginners

I am posting in my blog new tutorials for beginners who are going to start iPhone developement.
https://github.com/gopinathdev/iPhone-Development-Tutorials

Keep visiting i will post new tutorials ..

Setting Image for TabBar


UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg"] 
    resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage:
        [UIImage imageNamed:@"tab_select_indicator"]];

Setting Image for NavigationBar


UIImage *gradientImage44 = [[UIImage imageNamed:@"surf_gradient_textured_44"] 
        resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

[[UINavigationBar appearance] setBackgroundImage:gradientImage44 
        forBarMetrics:UIBarMetricsDefault];

Adding Image to UIView with out UIImageView


Setting the Image to UIView with out UIImageView.   
[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_sand"]]];    

Show or Hide StatusBar

In Application's Resource  folder have app-info.plist file, set the
property Status bar is initially hidden make yes/no.

Changing status bar style


In AppDelegate's "didFinishLaunchingWithOptions" method we can usually set this method for status bar visibulity.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];

Monday, 27 February 2012

Solving Webview bounces problem


for (id subview in webView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;

Reading Text fille content from Application Bundle



NSString *filePath = [[NSBundle mainBundle] pathForResource:@"EAP" ofType:@"txt"];

NSString *strData = [[NSString alloc] initWithContentsOfFile:filePath];
NSLog(@"Info :%@",strData);

Friday, 24 February 2012

TBXML Parser Sample

TBXML is the best XML parser with memory and performance aspectives.You can download sample source at https://github.com/gopinathdev/TBXML-Parser 

Lazy Loading sample

Best sample for lazy loading for images in Table View. If you want more details with source code visit at https://github.com/gopinathdev/lazyload

Objective-C XML Parsers


Before we begin, I wanted to make sure everyone is aware of the most important difference between XML parsers: whether the parser is a SAX or a DOM parser.
  • SAX parser is one where your code is notified as the parser walks through the XML tree, and you are responsible for keeping track of state and constructing any objects you might want to keep track of the data as the parser marches through.
  • A DOM parser reads the entire document and builds up an in-memory representation that you can query for different elements. Often, you can even construct XPath queries to pull out particular pieces.
TBXML is the best one parsers avialble in Objective C with performance and memory prospectives.

Monday, 20 February 2012

Synchronous and Asynchronous Request Processing


Synchronous Request Handling:
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost/json"]];
NSURLResponse *response = nil;
NSError *error = nil;
//getting the data
NSData *newData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//json parse
NSString *responseString = [[NSString alloc] initWithData:newData encoding:NSUTF8StringEncoding];
NSDictionary *jsonObject = [responseString JSONValue];
//Accessing JSON content
NSLog(@"type :  %@", [jsonObject objectForKey:@"Type"] );
Some explanations :
response is the url response for the json call
error is error returned by NSURLConnection
newData is data returned by the server
Notice that you can cast the JSON deserialized data into a NSDictionnary or anNSMutuableArray.

Asynchronous Request Handling:
To make an Asynchronous call we’ll need to use NSURLConnection withinitWithRequest method, then we need to implement differents other methods to handle the finish of data loading, error handling etc.
//in the viewDidLoad
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost/json"]];//asynchronous call
[[NSURLConnection alloc] initWithRequest:request delegate:self];
Implementing delegate methods :
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"%@", error);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    [responseData release];
    NSDictionary *jsonObject = [responseString JSONValue];
    NSLog(@"type :  %@", [jsonObject objectForKey:@"Type"] );
    [connection release];
}