【发布时间】:2013-01-07 16:42:07
【问题描述】:
我已经使用来自 MagicalRecord(核心数据包装器)的查询结果填充了 NSArray。我需要从cellForRowAtIndexPath: 中获取这些结果并将它们显示在UITableView 中的自定义单元格中,但索引引用另一个已选择的UITableView。
我有两个UITableViews;一个包含客户列表,另一个包含每个客户的约会列表。当用户选择客户时,代码会查找该客户的所有约会。因此,第二个表视图不涉及索引)。
第一个表视图有一个客户列表;当用户选择其中一个客户端时,第二个表视图将填充该选定客户端的约会列表。因此index.row 引用第一个UITableView 而第二个没有它可以引用的索引。我只是将apptDataArrray 的内容转储到单元格中。
这是我的代码:
if(tableView.tag == 2) { // appointment info
static NSString *cellIdentifier = @"apptListCell";
ApptCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[ApptCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
// configure the cell...
AppointmentInfo *currentAppointment = [apptDataArray objectAtIndex: 0]; // go through the array <---- TODO
// Set the dateFormatter format
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // start date/time
[timeFormatter setDateFormat:@"HH:mm:ss"]; // end time
UILabel *label = (UILabel *)[cell viewWithTag:3]; // display start date/time (NEEDS TO BE LOCALIZED!)<----- TODO????
label.text = [dateFormatter stringFromDate:currentAppointment.aStartTime];
label = (UILabel *)[cell viewWithTag:4]; // display end time
label.text = [timeFormatter stringFromDate:currentAppointment.aEndTime];
label = (UILabel *)[cell viewWithTag:5]; // display service tech name
label.text = currentAppointment.aServiceTech;
return cell;
}
我的问题是:在// configure the cell 下方的行中,我如何在每次调用cellForRowAtIndexPath: 时遍历apptDataArray,因为没有可应用于此数组的索引?
【问题讨论】:
-
数组怎么没有索引?它只包含一个对象吗?如果没有索引,那么数组和cellForRowAtIndexPath是什么关系?
标签: objective-c cocoa-touch nsarray uitableview