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