1
我有一个带有类别列表的tableview。如果用户在添加按钮上点击带有文本框的alertview并且出现“ok”按钮,并且在文本框中输入的文本应该被添加到表格视图中。我能够添加它,但是它没有被添加到plist.so如果我们转向另一种观点,回来就会消失,如何让它保持那样。将动态输入的数据保存到plist
-(void)viewDidLoad
{
NSString *fileForCategoryList = [[NSBundle mainBundle] pathForResource:kCATEGORY_LIST ofType:kP_List];
self.arrayForCategories = [[NSMutableArray alloc]initWithContentsOfFile:fileForCategoryList];
}
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self.arrayForCategories removeObjectAtIndex:indexPath.row];
[self.tableViewC reloadData];
}
else if (editingStyle == UITableViewCellEditingStyleInsert)
{
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:kYOUR_TITLE message:kEMPTY delegate:self cancelButtonTitle:kCANCEL otherButtonTitles:kOK, nil];
self.myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[self.myTextField setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:self.myTextField];
[myAlertView show];
[myAlertView release];
}
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if ([self.myTextField text])
{
[self.arrayForCategories addObject:[self.myTextField text]];
}
[self.tableViewC reloadData];
}
你能给我一点代码或任何相关的链接吗? – Chandu 2011-12-14 10:38:20