gpt4 book ai didi

ios - Prototype Cell 在 ios 7+ 上有空白内容

转载 作者:行者123 更新时间:2023-11-29 02:11:47 24 4
gpt4 key购买 nike

这个让我发疯 - 我不知道我错过了什么。

这是我的 ViewController。

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.


[self.tableView registerClass:[CurrentMatchCell class] forCellReuseIdentifier:@"CurrentMatchCell"];
self.tableView.delegate = self;
self.tableView.dataSource = self;

}

#pragma mark -
#pragma mark Table View Data Source Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSLog(@"1");
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"2");
return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"3");

CurrentMatchCell *cell = (CurrentMatchCell *)[tableView dequeueReusableCellWithIdentifier:@"CurrentMatchCell"];

if (cell == nil) {
NSLog(@"XXX");
}
[cell.matchDescription setText: @"Home Team vs Away Team"];

return cell;
}

这是应用程序的屏幕截图。

View Controller in scoreboard

委托(delegate)和数据源以编程方式设置。

enter image description here

单元格属性:

enter image description here enter image description here

还有 .h 文件:

@interface CurrentMatchesViewController : UIViewController <NSFetchedResultsControllerDelegate,UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

所以,我可以看到日志 1、2、3 被打印出来,单元格不为空,但我看不到我的内容。这是为什么?

我只看到一些空的白色单元格(即使我返回 0 或任何它每次都显示相同的内容)。

谢谢

最佳答案

如果您在 Storyboard中创建表格 View 和单元原型(prototype), Storyboard加载器将负责注册您在 Storyboard中定义的单元原型(prototype)。所以:

  1. 您不需要在代码中再次调用registerClass:forCellReuseIdentifier:。这实际上会弄乱你的 Storyboard设置。

  2. 您还可以使用 dequeueReusableCellWithIdentifier:forIndexPath: 而不是 dequeueReusableCellWithIdentifier:。该方法始终返回一个单元格,因此您不必进行 nil 检查。

编辑:如果这不起作用,请尝试在设置委托(delegate)/数据源后调用[self.tableView reloadData],或者设置委托(delegate)和数据 Storyboard中的源代码。

关于ios - Prototype Cell 在 ios 7+ 上有空白内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29218824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com