сохранение данных в текстовых полях и создание делегатов - PullRequest
0 голосов
/ 06 июля 2011

Пытаясь получить текстовое поле для автоматического сохранения и сохранения данных, я хочу иметь возможность вернуться к представлению, и данные остаются до тех пор, пока они не будут снова отредактированы.

пока у меня есть эти ...

@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

данные в текстовом поле не сохраняются.Спасибо

1 Ответ

0 голосов
/ 06 июля 2011

Что делает эта функция?

-(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];
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...