【问题标题】:What call should I be using instead of this deprecated method? [closed]我应该使用什么调用来代替这种不推荐使用的方法? [关闭]
【发布时间】:2012-01-31 07:02:29
【问题描述】:

我有一个 UITableViewController 可以动态创建可调整大小的单元格。单元格会根据文本内容和字体大小更改单元格的大小。 (在这里找到一个提示。)

它使用对以下已弃用的方法的调用:

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

我无法弄清楚要改用哪种方法并保留我的功能。 Apple 文档中没有参考。

我该如何解决这个问题?

【问题讨论】:

标签: iphone ios cocoa-touch uitableview deprecated


【解决方案1】:

The documentation 特别声明:

在 iOS 3.0 中已弃用。 请改用 initWithStyle:reuseIdentifier:

【讨论】:

  • 我搜索了 initWithFrame 并发现了错误的 initWithFrame,在其中我没有找到对这些信息的引用。我的坏:(
【解决方案2】:

试试这样的。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Standard"];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Standard"] autorelease];
}

【讨论】:

    【解决方案3】:
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    

    【讨论】:

      猜你喜欢
      • 2017-09-24
      • 2022-11-28
      • 2022-08-08
      • 1970-01-01
      • 2013-12-30
      • 2019-09-15
      • 1970-01-01
      相关资源
      最近更新 更多