Changing The Back Button To Say Something Other Than The Previous Views Title You can’t change the button text in the new view, you need to do it before the view is shown by simply changing the previous views title before triggering the new view: [self.navigationItem setTitle:@”Back”]; [self.navigationController pushViewController:Viewer animated:YES]; Adding An Info Button That […]
All posts by
Change View Size
You may want to make a reduced size view for say an input box of some sort or a view that will be used at the same size for both iPhone and iPad devices. Setting the View Size Select the view. In the attributes tab ensure that ‘Staus Bar’, ‘Top Bar’ and ‘Bottom Bar’ are […]
Using The Document Directory To Store Files
Show contents of Documents directory NSLog(@”Documents directory: %@”, [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]); Does File Exist NSString *path; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@”SomeDirectory”]; path = [path stringByAppendingPathComponent:@”SomeFileName”]; if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { Delete File NSString *path; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@”SomeDirectory”]; path = [path stringByAppendingPathComponent:@”SomeFileName”]; […]
Web View General
Adding a simple WebView to a view In #ViewController.h IBOutlet UIWebView *webView1; In Interface Builder Drag the Web View onto the view Connect the webView outlet to it Displaying an Internet URL E.g. in #ViewController.m ViewDidLoad: NSString *urlAddress = @”http://www.google.com”; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView1 loadRequest:requestObj]; Setting The Zoom […]
Read & Use Files
Display image from file UIImage *image1 = [[UIImage alloc] initWithContentsOfFile:filePath]; if (image1) { imageView.image = image1; [image1 release]; }
Output Text File Contents
Example converting a NSData file to a string for display NSString *s = [[[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding] autorelease]; NSLog(@”File Contents = %@”, s);
Creating A Delegate Callback
Often you need a class to call back a method of its owner. In this example MainClass is the class that needs to be called back and SubClass is the class that will need to call back a method in the MainClass. //You can copy the entire block below and then use find and replace […]
Message Box (Action Sheet) General
Show a main window message box Alert View will automatically adjust for landscape orientation UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"The username and password entered are not valid" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; ; Show A Message Box If ActionSheet doesn't auto adjust for landscape orientation check the following:- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLand scapeRight]; needed in applicationDidFinishLaunching? Supported […]
Creating Simple Code Files
To create a .m and .h file pair to use for shared functions etc Create Files Menu > File > New File > Mac OS X > C and C++ > C File Name it and ensure you change the extension from .c to .m Add to NewFile.h #import <UIKit/UIKit.h> Include Add import to the […]
Using Table View
Refresh Table View [tableView1 reloadData]; Scroll To Top [tableView1 setContentOffset:CGPointZero animated:NO]; Scroll To Row [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:NO];