0
我无法设置我的表格视图。 我有一个TableView“条目”哪里会有我的条目列表。 我有一个秒表TableView“AddEntry”,我有几个文本框,它将定义一个对象的属性。在按下“添加”后,对象名称将显示在“条目”TableView中。在表格视图中替换和编辑对象。 (目标C)
问题来了:我希望能够通过点击行来编辑Objects属性。
因此,例如:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:kEditSegueIdentifier]) {
edited = YES;
AddEntry *controller = [[[segue destinationViewController] viewControllers] objectAtIndex:0];
EntryObject *entry = self.entryObjectArray[self.indexPathInt];
controller.property1 = entry.property1;
controller.property2 = entry.property2;
controller.property3 = entry.property3;
}
}
稍后将填补文本框在“的AddEntry”视图与所选对象的属性。到现在为止还挺好。
如果我现在(无论是否更改对象属性)单击“完成”此方法将被调用,它将创建一个新的行与一个新的创建的对象,这是我想编辑完全相同。
- (void)saveEntryDetails:(EntryObject *)entry {
if (edited == YES) {
[self.entryObjectArray replaceObjectAtIndex:self.indexPathInt withObject:entry];
}
[self.entryObjectArray addObject:entry];
if (self.entryObjectArray.count < 1) {
NSArray *indexPaths = @[[NSIndexPath indexPathForRow:[self.entryObjectArray count] inSection:0]];
[self.tableView insertRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationFade];
}
else {
NSArray *indexPaths = @[[NSIndexPath indexPathForRow:[self.entryObjectArray count]-1 inSection:0]];
[self.tableView insertRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationFade];
}
}
我该如何区分“新建对象”和“对象已编辑”?
另外我该如何更换我的数组中的编辑对象?