我试图计算我的数组以设置为表中的行数,然后将其乘以 2,因为我在每个单元格之间有一个不可见的单元格,以使单元格看起来是分开的。每次我尝试构建时,都会收到此错误:
由于未捕获的异常“NSRangeException”而终止应用程序,原因:“ * -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]”
这是我正在使用的代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [xmlParser.calls count] * 2;
}
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
static NSString *CELL_ID2 = @"SOME_STUPID_ID2";
JointCAD *currentCall = [[xmlParser calls] objectAtIndex:indexPath.row];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"texture3.png"]];
[self.tableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"texture3.png"]]];
if (indexPath.row % 2 == 1) {
UITableViewCell * cell2 = [tableView dequeueReusableCellWithIdentifier:CELL_ID2];
if (cell2 == nil) {
cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CELL_ID2];
[cell2.contentView setAlpha:0];
[cell2 setUserInteractionEnabled:NO];
[cell2 setBackgroundColor:[UIColor clearColor]];
}
return cell2;
}
TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.callTypeLabel.text = currentCall.currentCallType;
cell.locationLabel.text = currentCall.location;
cell.unitsLabel.text = currentCall.units;
cell.stationLabel.text = [@"Station: " stringByAppendingString:currentCall.station];
cell.contentView.layer.backgroundColor = [UIColor whiteColor].CGColor;
cell.contentView.layer.frame = CGRectMake(0, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height);
cell.contentView.layer.borderWidth = 1.0;
cell.contentView.layer.borderColor = [UIColor blackColor].CGColor;
if ([currentCall.county isEqualToString:@"W"]) {
cell.countyImageView.image = [UIImage imageNamed:@"blue.png"];
} else {
cell.countyImageView.image = [UIImage imageNamed:@"green.png"];
}
if ([currentCall.callType isEqualToString:@"F"]) {
cell.callTypeImageView.image = [UIImage imageNamed:@"red.png"];
} else {
cell.callTypeImageView.image = [UIImage imageNamed:@"yellow.png"];
}
return cell;
}