テーブルビューにデータを保存するのに問題があります。
これは、テーブルビューをポップして注文したすべての料理を表示するボタンを備えたメニューアプリです。NSMutableArrayを使用してデータを保存していますが、テーブルビューを閉じると、テーブル内のデータが表示されます。空のテーブルである初期ステータスにリセットされます。
この問題を解決するにはどうすればよいですか、助けてくれてありがとう!
FPPopoverライブラリを使用して、ポップオーバーテーブルビューを表示しています。コードは次のとおりです。
- (IBAction)revealOrderList:(id)sender
{
SAFE_ARC_RELEASE(popover); popover=nil;
OrderListViewController *controller = [[OrderListViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:controller];
SAFE_ARC_RELEASE(controller); controller=nil;
popover = [[FPPopoverController alloc] initWithViewController:nc];
popover.tint = FPPopoverDefaultTint;
popover.contentSize = CGSizeMake(300, 500);
[popover presentPopoverFromView:sender];
}
そして、ポップオーバーテーブルビューでは:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
orderList = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];
//add the add button
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
}
- (void)insertNewObject
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add new thing"
message:@""
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
//Set the style of UIAlertView
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
//Show the UIAlertView
[alert show];
}