我有一个UITableView有五个部分.正如标题描述的那样,仅为前四个调用了cellForRowAtIndexPath.已经建立了有关数据源和委托的所有连接.此外,我的numberOfSectionsInTableView清楚地返回5.打印出cellForRowAtIndexPath中的部分数量显示正确的数字,从而确认不会为所有部分调用cellForRowAtIndexPath.到底是怎么回事?我很难找到这个问题的答案,但找不到答案.如果已经回答,请原谅我并指出正确的方向.
我的cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [theTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
switch (indexPath.section) {
case 0:
cell.textLabel.text = ticket.description;
break;
case 1:
cell.textLabel.text = ticket.ticketStatus;
break;
case 2:
cell.textLabel.text = ticket.priority;
break;
case 3:
cell.textLabel.text = ticket.customerOfficePhone;
break;
case 4: {
//This never ever gets executed
Comment *comment = [ticket.comments objectAtIndex:indexPath.row];
cell.textLabel.text = comment.commentContent;
break;
}
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我的numberOfSectionsInTableView:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 5;
}
Run Code Online (Sandbox Code Playgroud)
我的numberOfRowsInSection:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger numberOfRows;
if (section == 4) {
numberOfRows = [ticket.comments count];
}
else {
numberOfRows = 1;
}
return numberOfRows;
}
Run Code Online (Sandbox Code Playgroud)
任何建议表示赞赏.提前致谢.
啊,哈!我想到了.我忘记了我已经为我的表视图硬编码了帧,并将其添加为子视图,并禁用了滚动视图.不幸的是,滚动视图和tableview在高度方面都太小而无法容纳第五部分,我认为这是除了第五部分之外的所有部分都要调用cellForRowAtIndexPath的原因.重新调整我的表格视图的高度和滚动视图更大一点已经解决了我的问题.
| 归档时间: |
|
| 查看次数: |
3034 次 |
| 最近记录: |