Note that application bundle files are read only. Getting path for a file in the application bundle //Get pointer to application bundle NSBundle *applicationBundle = [NSBundle mainBundle]; //Get path to a resource file in the bundle NSString *path = [applicationBundle pathForResource:@”myImageName” ofType:@”png”]; //Returns nil if not found
All posts by
Checking which files will be included in the application bundle
When you add resource files to a project *images, audio, nib, etc) they will automatically be bundled with your application. To see which files are being bundled with the application In the project window open the ‘Targets’ group and then your project group within it. ‘Copy Bundle Resources’ shows all of the bundled files in […]
Binary Saving and Loading
NS Data //********** STORE NSDATA ********** NSString *FilePath = [NSHomeDirectory() stringByAppendingPathComponent:@”Library/Caches/users.xml”]; [FileData writeToFile:FilePath atomically:YES]; //Write it overwriting any previous file (atomically writes to a temporary location before copying to permanent – good protection in case app should crash) //********** GET NSDATA ********** NSString *FilePath; NSData *FileData; NSString *FilePath = [NSHomeDirectory() stringByAppendingPathComponent:@”Library/Caches/users.xml”]; FileData = [NSData dataWithContentsOfFile:FilePath]; […]
Files
Project Files .xib MainWindow_iPhone.xib and MainWindow_iPad.xib contain the interface for your application. Double click to open in the interface builder. .plist ApName-Info.plist is the info property list which contains a list of the key-value pairs. These values specify things like the icon to display on the home screen, if the app needs a persistant WiFi […]
Using Archiving
When a class conforms to the NSCoding protocol it can be archived and later loaded into the application. Archiving is very simple to use. To make a class suitable for archiving you simply need to use the NSCoding delegate and implement the encodeWithEncoder and initWithEncoder funcitons. The class is then ready to be stored and […]
Taking A Picture
Example With Camera Button In Top Navigation Bar In #ViewController.h @interface #ViewController : UIViewController { In #ViewController.m //********** INIT ********** – (id)init { [super initWithNibName:@”ItemDetailViewController” bundle:nil]; //—– ADD CAMERA BUTTON TO NAVIGATION BAR —– UIBarButtonItem *cameraBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(takePicture:)]; [[self navigationItem] setRightBarButtonItem:cameraBarButtonItem]; //Add to nav bar when this view controller is on […]
Dictionary Objects
NSMutableDictionary is a collection object similar to an array (NSArray). However an NSArray is an ordered list you access using an index value. Dictionary objects are not ordered and instead each object has a key (usually a string) which you use to access it. If you add an object to a dictionary using an existing […]
Passing Data To Another View
An Example Using A Class In #ViewController.h that you want to pass data to #import @class MyClassName; @interface #ViewController : UIViewController { MyClassName *myClass1; } @property (nonatomic, assign) MyClassName *myClass1; In #ViewController.m that you want to pass data to //Add import: #import “MyClassName.h” //Add synthesize: @implementation #ViewController @synthesize myClass1; //Deal with data: //********** VIEW WILL […]
ADDING OBJECTS TO VIEWS
Adding Objects To A View Declare The Inputs And Output in #ViewController.h Declare the objects you will output to (control from code) and methods for the objects providing input. Examples: IBOutlet UILabel *SomeLabel1; IBOutlet UILabel *SomeLabel2; IBOutlet UITextField *SomeTextField1; //### Remember to release any view objects you add in viewDidUnload and dealloc ### } – […]
UINavigationController For Dynamic Views Stack
UINavigationController provides a dynamic stack of views created at run time with a navigation bar at the top. For many applications this is used to provide all of the views the user sees. Useful Documentation iOS Reference Adding To A Project Create an App as normal with the main view XIB Create at least 1 […]