iOS开发:任务管理与iPad界面布局实现
1. KVC在任务管理中的应用
在任务管理的开发中,我们使用键值编码(KVC)来设置属性,而非直接设置委托。KVC的好处在于它能让代码与其他类的接口解耦,减少类之间的依赖。
例如,我们不直接调用 setDelegate: 方法,而是使用KVC来设置委托和选择信息。以下是将选中的任务和行索引放入字典传递给详情视图控制器的代码:
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"];
}
通过
超级会员免费看
订阅专栏 解锁全文
80

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



