【问题标题】:Unsupported configuration prototype table cells must have reuse identifiers不受支持的配置原型表单元格必须具有重用标识符
【发布时间】:2015-07-26 06:18:53
【问题描述】:

我在ViewDidLoad 中构建了一个UITableView,如下所示:

- (void)viewDidLoad
{
    CGSize viewSize = self.view.frame.size;
mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 35, viewSize.width, viewSize.height -149)];
[mainScroll setPagingEnabled:YES];
[mainScroll setShowsHorizontalScrollIndicator:NO];
[mainScroll setDelegate:self];
[mainScroll setTag:101010];

    // #1
    UIScrollView *scroll1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, viewSize.width, viewSize.height -149)];
    UITableView *table101 = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, viewSize.width, viewSize.height -149) style:UITableViewStylePlain];
    [table101 setDataSource:self];
    [table101 setDelegate:self];
    [table101 setBackgroundColor:[UIColor clearColor]];
    [table101 setTag:101];
    [table101 setSeparatorStyle:UITableViewCellSeparatorStyleNone];

    [scroll1 addSubview:table101];

    // #2
    UIScrollView *scroll2 = [[UIScrollView alloc] initWithFrame:CGRectMake(viewSize.width, 0, viewSize.width, viewSize.height -149)];
    UITableView *table102 = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, viewSize.width, viewSize.height -149) style:UITableViewStylePlain];
    [table102 setDataSource:self];
    [table102 setDelegate:self];
    [table102 setBackgroundColor:[UIColor clearColor]];
    [table102 setTag:102];
    [table102 setSeparatorStyle:UITableViewCellSeparatorStyleNone];

    [scroll2 addSubview:table102];

[mainScroll addSubview:scroll1];
[mainScroll addSubview:scroll2];
[mainScroll setContentSize:CGSizeMake(viewSize.width *2, viewSize.height -149)];



}

TableViewCell我用这个:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];

    }

    NSMutableArray *mutableArray;

    if (tableView.tag == 101) {
        mutableArray = self.itemsInTable_Molhaq;

    } else if (tableView.tag == 102) {
        mutableArray = self.itemsInTable_Ziyarah;
    }

    NSString *labelString = [[mutableArray objectAtIndex:indexPath.row] objectForKey:@"Title"];
    NSInteger indentLevel = [[[mutableArray objectAtIndex:indexPath.row] objectForKey:@"Level"] intValue];

    [cell.textLabel setAttributedText:[self attributeString:labelString indentLevel:indentLevel]];

return cell;

}

一切正常,但 Xcode 向我展示了这一点:

Unsupported configuration prototype table cells must have reuse identifiers

我错过了什么?我能得到一些帮助吗?

【问题讨论】:

  • 这是情节提要编辑器的警告。检查您的 *.storyboard 文件和 this
  • 可能是您在情节提要上使用 tableview。根据此代码,它不会给出此错误。

标签: objective-c xcode uitableview


【解决方案1】:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath*)indexPath 
{
static NSString *cellIdentifier = @"wot";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

if (!cell)
    cell = [[UITableViewCell alloc] initWithStyle: someStyle reuseIdentifier: cellIdentifier];

return cell;
}

可能会有帮助。

【讨论】:

    【解决方案2】:

    错误的含义很清楚。您已经在情节提要中创建了一个原型单元,但没有给它一个标识符。转到情节提要并查看单元格的属性。填写标识符。

    【讨论】:

    • 我的情节提要中没有任何 TableView 对象,我在 ViewDidLoad 中创建了所有 TableView,请参阅上面的代码
    猜你喜欢
    • 2023-03-02
    • 1970-01-01
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多