我读通过大书呆子牧场iOS指南和我有一个关于这段代码这里的问题:究竟如何做的NSIndexPath行物业工作
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
}
BNRItem *p = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[p description]];
return cell;
}
BNRItemStore仅仅是一个数据存储对象和我已经在初始化方法中为它添加了五个BNRItem对象。他们的字符串描述然后被打印到UI。我的困惑具体是关于这条线的位置:
BNRItem *p = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[indexPath row]];
我明白这条线的方式是objectAtIndex:刚刚取回的BNRItemStore的项目,并将其赋值给变量。我有这样的问题是:
objectAtIndex:能够返回所有五个对象的变量* p与参数[indexPath行]?我的印象是indexPath对象只包含单个部分和单个行。所以行属性只会返回单行索引。在这里它看起来像数组正在循环,其5个内容返回到变量,然后打印到UI。或者这不是发生了什么?这里的行属性究竟在做什么?
清除它......希望Apple文档能够这样解释它,因为有很多这些数据源方法,它不完全清楚幕后发生了什么。 –
@MikaSchiller - 此文档可能会帮助您:http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/tableview_iphone/AboutTableViewsiPhone/AboutTableViewsiPhone.html –
快速的问题:比方说,我仍然有5项数据存储,我希望把第0 2项和第1节中3项所以首先我会做到这一点: - (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分 { \t如果(部分== 0){ \t \t返回2 \t} \t如果(部分== 1){ \t \t回3 \t}} –