Xcode“未声明标识符的使用" [英] Xcode "Use of undeclared identifier"

查看:39
本文介绍了Xcode“未声明标识符的使用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道很多人问这个问题,但所有答案都是特定的应用程序,所以我不明白如何为我的应用程序工作.

I know many people ask this but all the answers are specific apps so I don't understand how to work it for my app.

        tableData = [NSArray arrayWithObjects:@"Chocolate Brownie", @"Mushroom Risotto", nil];
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
    {
        return [tableData count];
    }

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

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
        }

        cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
        return cell;` 
    }

推荐答案

原因是 ut tableData 变量没有被保留并且你已经通过工厂方法分配了它并且已经自动释放了.

the reason being ut tableData variable is not retained and you have assigned it via factory method with is already autoreleased.

在 .h 文件中,使其保留属性并将此变量与 self.h 一起使用.在你的代码中.

in .h file, make it retain property and use this variable with self. in ur code.

@property(nonatomic,retain) NSArray *tableData;

以 .m 为单位,

@synthesize tableData;

然后像这样使用它:

self.tableData = [NSArray arrayWithObjects:@"Chocolate Brownie", @"Mushroom Risotto",      nil];

现在你不会得到任何错误,因为 tableData 现在被保留了.

now you wont get any error as tableData is now retained.

如果您不使用 ARC,请不要忘记在 dealloc 中释放它.

do not forget to release it in dealloc if you are not using ARC.

这篇关于Xcode“未声明标识符的使用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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