菜鸟教程小白 发表于 2022-12-13 03:58:58

ios - 原型(prototype)单元 ==nil xcode6


                                            <p><p>当我创建 <code>UITableView</code> 时,tableview 没有附带原型(prototype)单元格,因此我删除了原始 View 并添加了 <code>UITableView</code>。但是,当新的 tableview 创建时,原型(prototype)仍然没有出现,所以我将一个 tablecell 拖到 table view 中,并在 storyboard 中将标识符命名为“Cell”。但是,当我尝试将解析查询填充到 tableview 单元格中时,它一直在崩溃,所以我放了一个 cell==nil 并发现该单元格等于 nil。我想知道我做错了什么?或者是否有任何方法可以识别单元格? </p>

<p>我的代码:</p>

<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @&#34;Cell&#34;;

    UITableViewCell *cell = [tableView
                           dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
      cell = [
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:CellIdentifier];
    }

    PFObject *shop=;
    cell.textLabel.text = ;
    return cell;
}
</code></pre>

<p>我的手机
<img src="/image/QbRtj.png" alt="enter image description here"/> </p>

<p>更新:
<img src="/image/3DsAj.png" alt="enter image description here"/> </p>

<p> <img src="/image/YirVZ.png" alt="enter image description here"/> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>原始代码示例中的单元格标识符是“Cell1”,而 Storyboard 中的单元格标识符只是“Cell”。这些必须是相同的标识符。 </p>

<p>顺便说一句,如果你有单元原型(prototype),你不应该在 <code>cellForRowAtIndexPath</code> 中插入那个 <code>if (cell == nil) { ... }</code> 子句。 <code>cell</code> 不应为 <code>nil</code>,因此您应该诊断该问题,而不是手动实例化表格 View 单元格。此外,您指定了“自定义”的表格单元格类型,但似乎像“基本”一样处理它。除非您真的为单元格使用自定义子类,否则我不会使用“自定义”单元格类型。</p>

<p>如果您的应用仍然崩溃,问题是错误信息是否相同。请使用您可能收到的任何错误消息的全文(特别是控制台中显示的内容)更新您的原始问题。如果您有堆栈跟踪,也请与我们分享。</p>

<p>另请引用<a href="http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1" rel="noreferrer noopener nofollow">So my app crashed, now what?</a>当您有错误时为总法律顾问。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 原型(prototype)单元 ==nil xcode6,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/27470188/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/27470188/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 原型(prototype)单元 ==nil xcode6