问题描述
我有一个 PFQueryTableViewController 的子类,我试图在容器视图(作为子视图)中显示它.我的问题是我无法在表格视图中显示自定义单元格.我已经通过调试验证了以下内容:
I have a subclass of PFQueryTableViewController that I am trying to show in a container view (as a subview). My problem is that I cannot get the custom cells to show in the tableview. I have verified the following via debugging:
- tableview 正在被添加到父视图中
- tableview 是一个 PFQueryTableView 控制器,因为它包括默认的拉动刷新
- PFQuery 返回正确数量的对象
- 正在调用 CellForRowAtIndexPath 方法并迭代正确的次数
- 来自 Parse 的正确数据被传递到单元格中的不同标签
- 标签通过我的 UITableViewCell 子类中的 IBOulet 连接.当我尝试访问标签时,它在访问子类和标签时正常工作
我在这里一切正常,只是单元格实际出现了!我错过了什么?
I have everything working here correctly except that the cell actually shows up! What am I missing?
这是我的 cellForRowAtIndexPath 代码:
This is my cellForRowAtIndexPath code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{
static NSString *CellIdentifier = @"RoundCell";
RoundCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil)
{
cell = [[RoundCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// get string values from Parse
NSString * teeString =[object objectForKey:@"roundTee"];
NSString* courseString = [object objectForKey:@"roundCourse"];
NSString * courseString2 = [[courseString stringByAppendingString:@" - "]stringByAppendingString:teeString];
NSString * dateString = [object objectForKey:@"roundDate"];
NSString * scoreString = [object objectForKey:@"roundScore"];
NSString * differentialString = [object objectForKey:@"roundDifferential"];
cell.courseNameCell.text = courseString2;
cell.dateCell.text = dateString;
cell.scoreCell.text= scoreString;
cell.differentialCell.text=differentialString;
return cell;
}
推荐答案
正确的方法是在 cellForRowAtIndexPath 中调用自定义单元格.
The correct method is to call the custom cell in cellForRowAtIndexPath.
检查两个基本事项:
1.在情节提要上单击属性检查器中的单元格检查该单元格是否具有正确的标识符
2.以这种方式设置 cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{
CustomCell *cell = (CustomCell * )[self.tableView dequeueReusableCellWithIdentifier:@"YOUR CELL NAME" forIndexPath:indexPath];
所以在你的情况下尝试:
So in your case try:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{
CustomCell *cell = (CustomCell * )[self.tableView dequeueReusableCellWithIdentifier:@"YOUR CELL NAME" forIndexPath:indexPath];
NSString * teeString =[object objectForKey:@"roundTee"];
NSString* courseString = [object objectForKey:@"roundCourse"];
NSString * courseString2 = [[courseString stringByAppendingString:@" - "]stringByAppendingString:teeString];
NSString * dateString = [object objectForKey:@"roundDate"];
NSString * scoreString = [object objectForKey:@"roundScore"];
NSString * differentialString = [object objectForKey:@"roundDifferential"];
cell.courseNameCell.text = courseString2;
cell.dateCell.text = dateString;
cell.scoreCell.text= scoreString;
cell.differentialCell.text=differentialString;
return cell;
}
不要忘记在 File.m 中导入自定义单元格的子类
Do not forget to import the subclass of custom cell in your File.m
#import "YourCustomCell.h"
并在身份检查器中设置单元格
and set the cell in the identity inspector
这篇关于PFQueryTableViewController 不显示自定义单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!