【发布时间】:2011-11-08 15:52:13
【问题描述】:
我需要一些帮助来保存自定义细节视图控制器。在我的表格视图中,我有一个添加和编辑按钮,用户可以在其中添加和删除自定义单元格。每个单元格都进入同一个自定义视图,我唯一的问题是有什么方法可以使用 SQlite 或其他数据库保存每个单元格?我只是不想创建大量的视图控制器并使用 NSUserDefaults 保存每个单元格。
我的代码:
表。 h =
IBOutlet UITableView *warrantyTableView;
NSMutableArray *data;
IBOutlet UITextField *tableCellText;
IBOutlet UITableView *mainTableView;
IBOutlet UINavigationItem *navItem;
}
- (IBAction)addRowToTableView;
- (IBAction)editTable;
- (NSString *)dataFilePath;
- (IBAction)endText;
表.m =
- (NSString *)dataFilePath {
NSString *dataFilePath;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
dataFilePath = [[documentDirectory stringByAppendingPathComponent:@"applicationData.plist"] retain];
return dataFilePath;
}
- (void)saveData {
[NSKeyedArchiver archiveRootObject:[data copy] toFile:[self dataFilePath]];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
PushedViewController *pushedViewController = [[PushedViewController alloc] initWithNibName:@"PushedView" bundle:nil];
// ...
// Pass the selected object to the new view controller.
PushedViewController *ifView = [[PushedViewController alloc] initWithNibName:@"PushedView" bundle:nil];
[self.navigationController pushViewController:ifView animated:YES];
[ifView release];
}
【问题讨论】:
标签: database xcode sqlite tableview detailsview