我在我的UITableView上顯示2個自定義單元格。我展示他們像這樣:索引超出UITableView與2個自定義單元
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"StepsViewCell";
static NSString *simpleTableIdentifier2 = @"descViewCell";
if(indexPath.row == 0) {
UITableViewCell *cell = nil;
cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier2];
if(!cell) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"descViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.textLabel.text = [descLabel objectAtIndex:indexPath.row];
return cell;
}
else {
StepViewCell *cell = nil;
cell = (StepViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if(!cell) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"StepsViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.stepTextLbl.text = [stepLabel objectAtIndex:indexPath.row];
[cell.thumbImage setImage:[UIImage imageNamed: @"full_breakfast.jpg"] forState:UIControlStateNormal];
return cell;
}
}
我使用下面的代碼descViewCell始終爲1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [stepLabel count] +1;
}
這工作計數他們,但是我得到index (5) beyond bounds (5)
當我向下滾動至底部的UITableView和它崩潰。我究竟做錯了什麼?