Uitableview io正在查找插入和取消模式
在使用UINavigationBar和UITableView时,我一直在寻找一个好的模式来实现插入然后取消模式 我在我的TeamsViewController导航栏中有一个“插入”按钮 当我运行时,它运行以下代码:Uitableview io正在查找插入和取消模式,uitableview,uinavigationbar,Uitableview,Uinavigationbar,在使用UINavigationBar和UITableView时,我一直在寻找一个好的模式来实现插入然后取消模式 我在我的TeamsViewController导航栏中有一个“插入”按钮 当我运行时,它运行以下代码: -(void)insertTeam { if( !detailViewController ) { detailViewController = [[TeamDetailViewController alloc] init]; } if( !t
-(void)insertTeam
{
if( !detailViewController ) {
detailViewController = [[TeamDetailViewController alloc] init];
}
if( !teams ) {
teams = [NSMutableArray array];
}
Team *team = [[Team alloc] init];
[teams addObject:team];
int lastIndex = [teams count];
[detailViewController setEditingTeam:[teams objectAtIndex:lastIndex - 1]];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
[self presentModalViewController:navigationController animated:YES];
}
如果用户填写了所有信息,这很好,但是如果他们在下一个视图中单击“取消”,则我的阵列中有一个空对象
我相信有一个很好的模式可以实现这一点,但我已经查看了所有TableView示例代码、两本不同的ios书籍,并尝试用谷歌搜索,但还没有找到一个模式
我的想法如下:
但这看起来并不那么顺利,我想有更好的方法来实现这一点。TIA。我很想让TeamsViewController成为TeamDetailViewController的代表。该代表将实现一种方法,例如
-(void)teamCreated:(Team*)Team代码>,它将更新数组。因为在数组中有一个不完整的团队似乎没有意义,所以我会让TeamDetailViewController创建该团队,并在委托调用中传递回去。在取消时,除了弹出控制器外,无需执行任何操作