initWithFrame:reuseIdentifier:已弃用 [英] initWithFrame : reuseIdentifier : is deprecated

查看:319
本文介绍了initWithFrame:reuseIdentifier:已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我有一个Deprecations警告,initWithFrame:reuseIdentifier:已弃用

In my project i've got a Deprecations warning, initWithFrame : reuseIdentifier : is deprecated

我不知道它是什么意思,有人会告诉我怎么样解决此警告
谢谢

I don't know what it mean, could some one tell me how to resolve this warning thanks

这里是短代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    // Set up the cell...
    NSString *cellValue = [itemsList objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;

    return cell;
}

并且警告在该行:

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];


推荐答案

看看这个Apple的页面


Apple将在未来的SDK中删除未来的红色突出显示的功能和属性。

Here Red-Highlighted Functions and Properties will be Removed in Future by Apple in upcoming SDK.

以便我们应该避免它们创建应用程序时。

因为我们需要长期项目,应该不会崩溃。

不推荐使用的方法意味着它已被替换/退役但在当前版本的语言中仍然有效。应该避免它,并可能导致问题/错误。查看应列出可以使用的替代方法的文档。

a deprecated method means it has been replaced/retired but is still valid in current version of the language. it should be avoided and can cause problems/errors. check the documentation which should list an alternative method you can use.

在这里你应该使用方法

 - initWithStyle:reuseIdentifier: 

然后你的if循环看起来像这样

Then your if loop would look like this

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

这篇关于initWithFrame:reuseIdentifier:已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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