2011-07-06 9 views
-1

データフィールドを自動的に保存して保存しようとすると、ビューに戻ることができるようになり、データは再び編集されるまで残ります。テキストフィールドにデータを保存してデリゲートを作成

これまでのところ、私はこれを持っている...テキストフィールドで

@interface TableDatabaseViewController : UIViewController <UITextFieldDelegate> 
{ 

    Tables*table; 
    NSArray * tables; 
    IBOutlet UITextField * surname; 
    IBOutlet UITextField * seatNo; 
    IBOutlet UISegmentedControl * occupied; 
    IBOutlet UITextField * numberLabel; 
    int tapCount; 
    id <TableInfoDelgate> modTable; 

} 

@property (nonatomic, retain) Tables*table; 
@property (nonatomic, retain) NSArray * tables; 
@property (nonatomic, retain) IBOutlet UITextField * surname; 
@property (nonatomic, retain) IBOutlet UITextField * seatNo; 
@property (nonatomic, retain) IBOutlet UISegmentedControl* occupied; 
@property (nonatomic, retain) id <TableInfoDelgate> modTable; 
@property (nonatomic, retain) IBOutlet UITextField * numberLabel; 
@property int tapCount; 

-(id)initWithTables:(Tables*)t; 
//-(void)myFunction; 


@end 




@synthesize table, numberLabel,tables,tapCount, modTable, seatNo,surname, occupied; 


- (void)dealloc 
{ 
    self.numberLabel =nil; 
    self.surname = nil; 
    self.table = nil; 
    self.seatNo = nil; 
    [super dealloc]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 

-(void)myFunction 
{ 
    AddTableViewController * createController = [[AddTableViewController alloc] initWithNibName:@"AddTableViewController" bundle:nil]; 

    [self.navigationController pushViewController:createController animated:YES]; 

    [createController release]; 


} 

- (void)viewDidLoad 
{ 
    UIBarButtonItem * theButton = [[UIBarButtonItem alloc] initWithTitle:@"Order" style:UIBarButtonItemStyleBordered target:self action:@selector(myFunction)]; 

    self.navigationItem.rightBarButtonItem = theButton; 
    [theButton release]; 

    self.tables = [TableListBuilder getTables]; 

    self.numberLabel.text = [NSString stringWithFormat:@"%@", self.table.number]; 

    self.seatNo.text = self.table.seats; 
    self.surname.text = self.table.surname; 

// self.occupied.text = self.table.occupied; 



    [super viewDidLoad]; 

} 

-(void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:NO]; 

    [self.modTable modifyTableatIndex: nil andsurname:self.surname.text andseatNo:self.seatNo.text andoccupied: self.occupied]; 

} 

I also created a delegate which is: 


@protocol TableInfoDelgate <NSObject> 

-(void) modifyTableatIndex: (int) index andsurname: (NSString*) surname andseatNo: (NSString*) seatNo andoccupied: (BOOL) occupied; 

@end 

データが保存されていません。ありがとう

答えて

0

この機能は何をしますか?単純な値を格納するために

-(void) modifyTableatIndex: (int) index andsurname: (NSString*) surname andseatNo: (NSString*) seatNo andoccupied: (BOOL) occupied; 

NSUserDefaults

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
    [textField setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"storedTextValue"]; 
} 

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    [[NSUserDefaults standardUserDefaults] setObject:textField.text forKey:@"storedTextValue"]; 
    [[NSUserDefaults standardUserDefaults] synchronize]; 
} 
+0

に見て最初のfuctionは、私は、私はしかし、viewWillAppearにエラーを取得して、これらのメソッドを挿入しようとした...変数を呼び出すために、セットアップに言われた代理人でありますat textField。 – Bradley

+0

textfieldをtextFieldインスタンス変数名に置き換えてください。 – adam

関連する問題