【问题标题】:UITableViewCell accessoryType doesn't work Xcode 6.0.3UITableViewCell accessoryType 不起作用 Xcode 6.0.3
【发布时间】:2014-10-15 23:09:36
【问题描述】:

我正在测试一个非常简单的应用程序。我有一个带有以下代码的表格视图,用于设置单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MyBasicCell"];
    cell.textLabel.text=[phones objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDetailButton;

    return cell;
}

我在 UIViewController 中使用了 UITableView。我尝试了所有类型的附件类型,但没有显示。 我试图创建另一个作为 UITableViewController 子类的类,它工作正常(与上面的源代码相同)。 是 Xcode 6 中的错误还是 Apple 开始放弃 Objective C?
更新:Here 是整个项目。

【问题讨论】:

  • 我认为问题不在这里,您显示的代码应该在其他地方。你能显示更多细节吗?可能是整个项目。
  • 请检查我更新的项目。请使用 Xcode 6 构建
  • 谁能给出答案?我认为这是一个非常简单的问题,但我被困了不止一天。

标签: ios objective-c iphone


【解决方案1】:

终于找到原因了。我正在使用自动布局,但我不熟悉自动布局,所以我无法正确设置它(我猜)。所以我禁用了自动布局(和大小类)并调整了表格视图的自动调整大小,它适用于 iPhone 4"、4.7" 和 5.5"。

这是插图:

【讨论】:

    【解决方案2】:

    你必须初始化你的单元格。例如:

    static NSString *cellIdentifier = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    

    【讨论】:

    • 您好,我测试了您的代码,但事实并非如此。用storyboard很久了,不用初始化cell。
    • 我还注意到,当我支持“编辑模式”时,删除按钮不显示。使用 UITableViewController 的子类,它确实显示了删除按钮。好奇怪
    【解决方案3】:

    我有同样的问题,我的解决方法是在“viewDidAppear”中设置附件类型。

    -(void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        UITableViewCell *c = [yourTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
        [c setAccessoryType:UITableViewCellAccessoryCheckmark];
    }
    

    它对我有用。

    【讨论】:

    • 没用,抱歉
    【解决方案4】:

    如果您使用自动布局,请务必设置表格视图的边距

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多