UITableViewCell 子类化时出现问题(2 个警告)
根据 NIB(动态选项)中的自定义单元的文档,我有这个方法。 (视图本身不是 UITableViewController,但它已正确连接。)
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ReusableCell";
UITableViewCell *cell = (LoadGameCell *)
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[NSBundle mainBundle]
loadNibNamed:@"LoadGameCell" owner:self options:nil];
cell = loadGameCell;
self.loadGameCell = nil;
}
/*
cell setup
*/
return cell;
}
if 语句中的第一行是我遇到问题的地方。
Incompatible pointer types assigning to 'UITableViewCell *' from 'NSArray *'
Incompatible Objective-C types assigning 'struct NSArray *',
expected 'struct UITableViewCell *'
运行带有这些警告的应用程序时没有错误/崩溃,但我不想忽略/抑制它们。以后会更痛。
如果这不是上述警告的直接结果,那么还有另一个问题。我无法获取获取视图的方法,只能获取标签。 (也就是说,我可以自定义标签,但不能自定义它旁边的图像视图。)
Following the documentation on custom cells from a NIB (the Dynamic option), I have this method. (The view itself is not a UITableViewController, but it's hooked up properly.)
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ReusableCell";
UITableViewCell *cell = (LoadGameCell *)
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[NSBundle mainBundle]
loadNibNamed:@"LoadGameCell" owner:self options:nil];
cell = loadGameCell;
self.loadGameCell = nil;
}
/*
cell setup
*/
return cell;
}
The first line in the if
statement is the bit I'm having trouble with.
Incompatible pointer types assigning to 'UITableViewCell *' from 'NSArray *'
Incompatible Objective-C types assigning 'struct NSArray *',
expected 'struct UITableViewCell *'
No errors/crashes running the app with these warnings, but I'd rather not ignore/suppress them. It'll hurt a whole lot more later on.
If it isn't a direct result of the warnings above, there's another problem. I can't get the method to take views, only labels. (That is, I can customize a label, but not the image view it's sitting next to.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如文档将告诉您的那样,
loadNibNamed:owner:options:
返回一个数组。要访问 NIB 中的单元(假设它是 NIB 中唯一的根级对象),请对loadNibNamed:owner:options
的结果调用objectAtIndex:0
。As the documentation will tell you,
loadNibNamed:owner:options:
returns an array. To access the cell in the NIB (assuming it is the only root-level object in the NIB), callobjectAtIndex:0
on the result ofloadNibNamed:owner:options
.