是UITableView numberOfRowsInSection不打电话。但是cellForRowAtIndexPath并没有被调用。我不明白为什么不调用cellForRowAtIndexPath。如果我更改区段中的行数
return (allOfficedata.count >0)? allOfficedata.count + 1 : allOfficedata.count; 或
return [array count]+1;
if (allOfficedata.count >0) return [allOfficedata count] + 1;如果我给出返回数组计数,或者返回11,则不会调用cellforrowatindexpath;它的工作良好--我附加了代码Error
*由于非正常异常“NSRangeException”终止应用程序,原因:'* -__NSArrayM objectAtIndex::index 10超出界限0。9'
-(NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView==self.LeftMenuTable)
return leftOptions.count;
return [allOfficedata count]+1;
}
**********************************************************************
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView==self.LeftMenuTable)
return 60;
Feedmodel *fmodel=[allOfficedata objectAtIndex:indexPath.row];
NSString *checkType = fmodel.achievementType;
if (isPad)
{
if (indexPath.row == 0)
{
return (isPad)?300.0:434.0;
}
else if (indexPath.row == allOfficedata.count+1)
{return 30.0;}
else{
if (![checkType isEqualToString:@""] || [checkType isEqualToString:@"0"] || [checkType isEqualToString:@"1"])
return ([fmodel.feedCommentCount integerValue] > 0)?366:318;
else
return ([fmodel.feedCommentCount integerValue] > 0)?249:200;
}
return 0.0;
}
else
{
if (indexPath.row == 0)
{
return (isPad)?232.0:434.0;
}
else
{
if (![checkType isEqualToString:@""] || [checkType isEqualToString:@"0"] || [checkType isEqualToString:@"1"])
return ([fmodel.feedCommentCount integerValue] )?259:222;
else
return ([fmodel.feedCommentCount integerValue])?184:142;
}
return 0.0;
}
}
***************************************************************
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier3 = @"loadMore";
static NSString *CellIdentifier = @"TableViewCell";
if (tableView==self.LeftMenuTable)
{
TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
UIView *sepView=[[UIView alloc ]initWithFrame:CGRectMake(0,59, 250, 1)];
[cell.contentView addSubview:sepView];
[sepView setBackgroundColor:[UIColor grayColor]];
}
cell.cellTextLabel.textColor=[UIColor whiteColor];
[cell.cellTextLabel setText:[[leftOptions objectAtIndex:indexPath.row] valueForKey:@"name"]];
[cell.CellImageView setImage:[UIImage imageNamed:[[leftOptions objectAtIndex:indexPath.row] valueForKey:@"image"]]];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.backgroundColor=[UIColor clearColor];
return cell;
}
else
{
NSUInteger row = [indexPath row];
NSInteger countRoe = [allOfficedata count];
if (row == countRoe )
{
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier3];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier3];
}
cell.textLabel.text = @"LoadMore";
return cell;
}else
{
if (indexPath.row == 0)
{
//CellCallOutBox_Onboarding_iPad
//CellCalloutbox_Office_iPad
//CellCalloutbox_Office_iPhone
NSString *nibName;
if ([calloutOffice.is_empty_daily_mission isEqualToString:@"false"]) {
nibName = (isPad)?@"CellCalloutbox_Office_iPad":@"CellCalloutbox_Office_iPhone";
}
else if ([calloutOffice.is_empty_onboarding_mission isEqualToString:@"false"])
{
nibName = (isPad)?@"CellCallOutBox_Onboarding_iPad":@"CellCallOutBox_Onboarding_iPhone";
}
else if ([calloutOffice.is_empty_community_mission isEqualToString:@"false"])
{
nibName = (isPad)?@"CellCallOutBox_Onboarding_iPad":@"CellCallOutBox_Onboarding_iPhone";
}
CellCalloutbox_Office *cellcallout = (CellCalloutbox_Office *)[tableView dequeueReusableCellWithIdentifier:nibName];
if (cellcallout == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];
cellcallout = [nib objectAtIndex:0];
}
cellcallout.aMissionDelegate = self;
[cellcallout.btnVideoOfTheDay addTarget:self action:@selector(videoOfTheDay) forControlEvents:UIControlEventTouchUpInside];
cellcallout.backgroundColor=[UIColor clearColor];
[cellcallout setArraywithCallOut:calloutOffice expanded:isCallOutOfficeExpanded];
[cellcallout.btnBackCallout addTarget:self action:@selector(calloutBack) forControlEvents:UIControlEventTouchUpInside];
[cellcallout.btnDailyMission addTarget:self action:@selector(openCalloutDilyMission) forControlEvents:UIControlEventTouchUpInside];
return cellcallout;
}
Feedmodel *fmodel=[allOfficedata objectAtIndex:indexPath.row];
NSString *checkType = fmodel.achievementType;
if (![checkType isEqualToString:@""] || [checkType isEqualToString:@"0"] || [checkType isEqualToString:@"1"])
{
static NSString *simpleTableIdentifier = @"CellWithImageVideo";
CellWithImageVideo *cell = (CellWithImageVideo *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
NSString *nibNmaeForiPad = (([fmodel.feedCommentCount integerValue])?@"CellWithImage_Comment_iPad":@"Cell_WithImage_MyOffice_iPad");
NSString *nibNmaeForiPhone = (([fmodel.feedCommentCount integerValue])?@"CellWithImagewithComment_iPhone":@"CellWithImageVideo");
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:(isPad)?nibNmaeForiPad:nibNmaeForiPhone owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.backgroundColor=[UIColor clearColor];
cell.contentView.backgroundColor=[UIColor clearColor];
[cell setFeeddata:fmodel indexPath:indexPath];
[cell.hifiveBtn addTarget:self action:@selector(hifiveClickedMyOfiice:) forControlEvents:UIControlEventTouchUpInside];
[cell.playMintBtn addTarget:self action:@selector(getFeedDetails:) forControlEvents:UIControlEventTouchUpInside];
[cell.planToDoBtn addTarget:self action:@selector(planToDoClickedOffice:) forControlEvents:UIControlEventTouchUpInside];
[cell.userImageBtn addTarget:self action:@selector(gotouserProfile:) forControlEvents:UIControlEventTouchUpInside];
[cell.inspireBtn addTarget:self action:@selector(InspireClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.sendCommentBtn addTarget:self action:@selector(serverCommentPost:) forControlEvents:UIControlEventTouchUpInside];
[cell.btnCompliment addTarget:self action:@selector(getFeedCommentPopup:) forControlEvents:UIControlEventTouchUpInside];
cell.txtFldCommentField.delegate = self;
return cell;
}
else
{
static NSString *simpleTableIdentifier = @"CellWithoutImage";
NSString *nibNmaeForiPad = (([fmodel.feedCommentCount integerValue])?@"Cell_withoutImage_withcomment_iPad":@"Cell_withoutImage_Ipad_Office");
NSString *nibNmaeForiPhone = (([fmodel.feedCommentCount integerValue])?@"CellWithoutImagewithComment_iPhone":@"CellWithoutImage");
CellWithoutImage *cell = (CellWithoutImage *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:(isPad)?nibNmaeForiPad:nibNmaeForiPhone owner:self options:nil];
cell = [nib objectAtIndex:0];
}
[cell setFeeddata:fmodel indexPath:indexPath];
cell.backgroundColor=[UIColor clearColor];
cell.contentView.backgroundColor=[UIColor clearColor];
[cell.hifiveBtn addTarget:self action:@selector(hifiveClickedMyOfiice:) forControlEvents:UIControlEventTouchUpInside];
[cell.planToDoBtn addTarget:self action:@selector(planToDoClickedOffice:) forControlEvents:UIControlEventTouchUpInside];
[cell.userImageBtn addTarget:self action:@selector(gotouserProfile:) forControlEvents:UIControlEventTouchUpInside];
[cell.inspireBtn addTarget:self action:@selector(InspireClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.btnCompliment addTarget:self action:@selector(getFeedCommentPopup:) forControlEvents:UIControlEventTouchUpInside];
[cell.sendCommentBtn addTarget:self action:@selector(serverCommentPost:) forControlEvents:UIControlEventTouchUpInside];
[cell.btnTextMintTapped addTarget:self action:@selector(getFeedDetails:) forControlEvents:UIControlEventTouchUpInside];
cell.txtFldComment.delegate = self;
return cell;
}
}
}
}发布于 2015-02-06 13:49:54
您说的allOfficedata +1表示numberOfRowsInSection,但在heightForRowAtIndexPath中:您有以下一行:
Feedmodel *fmodel=[allOfficedata objectAtIndex:indexPath.row];这将导致您在最后一个单元格上崩溃,因此您需要检查它是否是最后一个单元格,如果它是最后一个单元格,则执行其他操作。
编辑:
此外,你似乎在做类似的事情在cellForIndexPath,
如果执行一些操作(indexPath == 0),但是在此之后,您将得到下一个单元格:
Feedmodel *fmodel=[allOfficedata objectAtIndex:indexPath.row];您应该-1来自indexPath.row,就像当前为单元格at获取的一样,假设indexPath.row == 1,您在索引1处请求对象,我认为应该要求0。当你到达最后一个单元格时,应用程序就会在上面的线路上崩溃。
编辑2:
因此,问题在于您要求allOfficedata提供一个不存在的索引,当您为行指定allOfficedata+1时,当它到达表中最后一个单元格的heightForRowAtIndexPath时,它要求从allOfficedata中获取不存在的索引的数据,因为它寻找您在numberOfRowsInSection中给出的+1
因此,假设allOfficedata的计数是10 (索引0-9),我们已经说过表中的行数是allOfficedata+1,所以它的11行(索引0-10)。
在heightForRowAtIndexPath中,我们得到了最后一个单元格(索引10),allOfficedata没有它,因为它的索引是0-9。请向allOfficedata请求索引10,它将崩溃。
发布于 2015-02-06 14:02:14
NSArray出界了。
因此,indexpath.row将为您提供正确的值,以确定数组在正确位置的值。
发布于 2015-02-06 14:14:02
除了行计数错误之外,cellForRowAtIndexPath从未被调用的最可能的原因是表视图认为没有要显示的行。
只有在需要单元格时才会调用cellForRowAtIndexPath。您的代码中似乎有高度非常高的单元格。无法看到任何用于区段标题视图或高度的代码。
因此,考虑到很大的高度,特别是对于第0行(根据您的代码是300或400 ),除非您向上滚动,否则不会有对此函数的多次调用。滚动时,应该会看到更多对单元格的调用。
还要检查你是否返回0的高度,因为这也可以阻止它试图显示的细胞,我认为,因为它不会被看到。
它将要求每一行的高度来估计所需的滚动条大小。
https://stackoverflow.com/questions/28366906
复制相似问题