我有一个在表视图中存储数据的问题。表视图不存储数据
这是一个菜单的应用程序,它会弹出一个表格视图,并显示他们所订购的所有菜肴,我使用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];
}
添加一些代码?如果卸载视图控制器,数据将随之一起发送。 – 2013-03-26 21:49:13
您的主要问题是您依赖视图或控制器来保存模型。 – sosborn 2013-03-26 22:19:43
那我该怎么办? – 2013-03-26 22:36:41