'UITableView' 没有 @interface 声明选择器 'initWithStyle:reuseIdentifiers [英] no @interface for 'UITableView' declares the selector 'initWithStyle:reuseIdentifiers

查看:30
本文介绍了'UITableView' 没有 @interface 声明选择器 'initWithStyle:reuseIdentifiers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 iOS 开发新手,正在寻求有关 UITableView 问题的帮助.

I'm new in iOS development, and i'm looking for some help on my UITableView issue.

好吧,我正在研究有关 UITableView 代码的所有内容,并且在开发过程中,当我尝试重用标识符时(以防界面上没有要创建的单元格),XCode 显示消息:

Well, i was studying everything about the UITableView code, and, during the development, when i'm trying to reuse the identifier (in case that there's no cell to create on the interface), the XCode shows the message:

'UITableView' 没有可见的@interface 声明了选择器 'initWithStyle:reuseIdentifier:"

"No visible @interface for 'UITableView' declares the selector 'initWithStyle:reuseIdentifier:"

代码如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"Cell";

    UITableView *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    if(cell ==nil)
    {
        cell = [[[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
    }

有人可以帮我吗?

推荐答案

UITableView *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

应该是

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

你应该分配一个 UITableViewCell 而不是 UITableView 就像你在这里所做的那样.

you should allocate a UITableViewCell not UITableView like what you've done here.

   //should be **UITableViewCell**
      cell = [[[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];

不要忘记稍后归还.

return cell;

这篇关于'UITableView' 没有 @interface 声明选择器 'initWithStyle:reuseIdentifiers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆