iOS开发:故事板与iPad特定视图控制器应用指南
1. KVC在任务列表与详情视图中的应用
在iOS开发里,KVC(键值编码)是一项强大的技术,它能让代码的耦合度降低。在处理任务列表和详情视图时,我们采用KVC而非直接设置委托,这样做的好处是代码无需了解其他类接口的具体细节。
比如在 BIDTaskListController 里,我们把选中的任务和选中行的索引放到一个字典里,再传递给详情视图控制器:
if ([destination respondsToSelector:@selector(setSelection:)]) {
// prepare selection info
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
id object = [self.tasks objectAtIndex:indexPath.row];
NSDictionary *selection = [NSDictionary dictionaryWithObjectsAndKeys:
indexPath, @"indexPath",
object, @"object",
nil];
[destination setValue:selection forKey:@"selection"];
}
超级会员免费看
订阅专栏 解锁全文
57

被折叠的 条评论
为什么被折叠?



