我有一张表格,其内容使用根据附加的分段控件的值提供的两个数据集中的一个填充。数据从网络中提取。分段UITable的不稳定性
当我在两个数据集之间来回移动时,应用程序崩溃,然后选择一个表格单元格。当我使用两个单独的表格而不是带有分段控件的单个表格时,该应用程序不会打嗝。以某种方式组合它们会使应用程序不稳定。
其中一个最大的错误是当我点击一个Acell的Acells并且它的加载时,我点击了segment index = 1,这会加载B.它会导致无法识别的选择器被发送。参数的含义o要发送到B表的表。
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier0;
if (choice == 0) {
CellIdentifier0 = @"ACell";
} else if (choice == 1) {
CellIdentifier0 = @"BCell";
}
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
if (cell == nil) {
if (choice == 0) {
[[NSBundle mainBundle] loadNibNamed:@"ACell" owner:self options:nil];
cell = ACell;
self.ACell = nil;
} else if (choice == 1) {
[[NSBundle mainBundle] loadNibNamed:@"BCell" owner:self options:nil];
cell = BCell;
self.BCell = nil;
}
}
if (choice == 0) {
[(ACell *)cell setA:(A*)[contentArray objectAtIndex:indexPath.row]];
} else if (choice == 1) {
[(BCell *)cell setB:(B*)[contentArray objectAtIndex:indexPath.row]];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (choice == 0) {
A = [contentArray objectAtIndex:indexPath.row];
[[NSNotificationCenter defaultCenter] postNotificationName:@"showA" object:A];
} else if (choice ==1) {
B = [contentArray objectAtIndex:indexPath.row];
[[NSNotificationCenter defaultCenter] postNotificationName:@"showB" object:B];
}
}
这可能是重复使用单元格的问题。没有**代码的**没有办法说。 – PengOne 2011-06-11 01:55:18
下面是代码 – lilzz 2011-06-11 04:38:00