Jump to content

iphone programming


1 post in this topic

Recommended Posts

Hi guys,

 

Need some help understanding xcode..

 

Firstly,I setup a navigation base app. when i drill down to 1st view, a table will appear. Once i selected a row, i would like the name of the row to be save somewhere.

 

Now when i go back to the main, and i drill down to 2nd view, the row that was select from 1st view will be display.

 

for 2nd view 1 use the following code and it works fine.

 

#import "PageTwoViewController.h"

 

@implementation PageTwoViewController

@synthesize field1;

@synthesize field2;

@synthesize field3;

@synthesize field4;

 

- (NSString *)dataFilePath {

NSArray *paths = NSSearchPathForDirectoriesInDomains(

NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

return [documentsDirectory stringByAppendingPathComponent:kFilename];

}

- (void)applicationWillTerminateNSNotification *)notification {

NSMutableArray *array = [[NSMutableArray alloc] init];

[array addObject:field1.text];

[array addObject:field2.text];

[array addObject:field3.text];

[array addObject:field4.text];

[array writeToFile:[self dataFilePath] atomically:YES];

[array release];

}

#pragma mark -

- (void)viewDidLoad {

 

NSString *filePath = [self dataFilePath];

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {

NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];

field1.text = [array objectAtIndex:0];

field2.text = [array objectAtIndex:1];

field3.text = [array objectAtIndex:2];

field4.text = [array objectAtIndex:3];

[array release];

}

 

 

UIApplication *app = [uIApplication sharedApplication];

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(applicationWillTerminate

name:UIApplicationWillTerminateNotification

object:app];

[super viewDidLoad];

}

 

- (void)viewDidUnload {

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

self.field1 = nil;

self.field2 = nil;

self.field3 = nil;

self.field4 = nil;

[super viewDidUnload];

}

- (void)dealloc {

[field1 release];

[field2 release];

[field3 release];

[field4 release];

[super dealloc];

}

@end

 

How do i copy the row that was selected in view 1 and display in view 2?

 

I can't seem to find the created datafile anywhere on my mac?

 

i had this header file:

 

#import <UIKit/UIKit.h>

 

#define kFilename @"dat.plist" ///problem lies here

 

@interface PageTwoViewController : UIViewController {

UITextField *field1;

UITextField *field2;

UITextField *field3;

UITextField *field4;

}

@property (nonatomic, retain) IBOutlet UITextField *field1;

@property (nonatomic, retain) IBOutlet UITextField *field2;

@property (nonatomic, retain) IBOutlet UITextField *field3;

@property (nonatomic, retain) IBOutlet UITextField *field4;

- (NSString *)dataFilePath;

- (void)applicationWillTerminate:(NSNotification *)notification;

@end

 

greatly appreciate the help.

 

Thx in advance.

 

Rgds

Link to comment
Share on other sites

 Share

×
×
  • Create New...