我想將自定義單元格添加到靜態UITableViewController
。我使用SWTableViewCell來獲取swipable單元格,並且我正在使用自定義的-xib作爲單元格佈局。索引1超出界限[0..0]與自定義單元格和SWTableViewCell
我似乎正常工作時,我只需要使用一個單元,但是當有一個以上我得到這個:Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
發生這種情況時,我使用dequeueReusableCellWithIdentifier
在cellForRowAtIndexPath
當第二單元應該出現(當我開始滾動時)。
這裏是我的代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
self.images = selectedReport.image;
imagesArray = [self.images.allObjects mutableCopy];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
[self.tableView registerNib:[UINib nibWithNibName:@"PictureCell" bundle:nil] forCellReuseIdentifier:@"PictureCell"];
}
- (NSInteger) tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger) section
{
if(section == 0){
return 10;
}else if(section == 1){
return imagesArray.count; //It is the second section which is dynamic
}
return 1;
}
- (UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath
{
static NSString* cellIdentifier = @"PictureCell";
if (indexPath.section == 0 || indexPath.section == 2)
{ //Takes the rows from the storyboard
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
else
{
NSLog(@"%i",indexPath.row);
NSLog(@"%i",indexPath.section);
PictureTableViewCell *cell = (PictureTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; //Crash here when indexPath.row == 1
[cell setCellHeight:cell.frame.size.height];
cell.containingTableView = tableView;
indexPath.section, indexPath.row];
Image *tempImage = imagesArray[indexPath.row];
cell.image.image = [UIImage imageWithData:tempImage.image];
cell.lblDescription.text = tempImage.image_description;
cell.rightUtilityButtons = [self rightButtons];
cell.delegate = self;
return cell;
}
}
我已經檢查了numberOfRowsInSection
回報2時,部分== 1
謝謝你的任何援助!
類檢查imagesArray不會空 – NANNAV
@NANNAV對不起?我已檢查numberOfRowsInSection返回2時段是1 – PaperThick