菜鸟教程小白 发表于 2022-12-11 17:45:00

ios - 未调用 ObjC 类方法。 GDB玩游戏?


                                            <p><p>我有一个自定义的 UITableViewController,我试图用它来管理 UITableView。我的代码在包含 UITableView 的主 UIViewController 中的流程如下:</p>

<pre><code>    _messagesTableVC = [ init];

    _allMessageTableView.dataSource = _messagesTableVC;
    _allMessageTableView.delegate = _messagesTableVC;

    ;
</code></pre>

<p><code>AllMessagesTableViewController</code> 自定义 UITableViewController 类已初始化,它执行所需的任何处理,我将 <code>_allMessageTableView</code>(UITableView)的委托(delegate)设置为我的自定义类。</p >

<p>当我运行此代码时,程序的行为就像自定义类不存在但没有发生错误一样。似乎没有调用自定义类中的任何方法,没有 init,没有 initWithCoder,什么都没有(我已经设置了断点并检查了;))。 </p>

<p>正如您在下面的屏幕截图中看到的,我在自定义类中的自定义方法 <code>refreshData</code> 之后设置了一个断点,我设置为返回 <code>YES</code>。我将 <code>refreshData</code> 的返回值分配给一个局部变量 <code>test</code>。</p>

<p>在调试器中:</p>

<ol>
<li><code>_messagesTableVC</code> 自定义类似乎不是 nil。 </li>
<li><code>test</code> 似乎不存在。</li>
<li>此处未显示,但是当我尝试在调试器中运行 <code></code> 时,它显示 <code>error: Execution was interrupted, reason: Attempted to dereference an invalid ObjC Object or send it一个无法识别的选择器。
进程已经返回到表达式求值前的状态。</code>。那么 <code>_messagesTableVC</code> 实际上是 nil 吗??</li>
</ol>

<p> <a href="/image/A0ZRS.png" rel="noreferrer noopener nofollow"><img src="/image/A0ZRS.png" alt="screenshots"/></a> </p>

<p>是什么导致了这些问题,或者 GDB 正在玩游戏?这是一个消息应用程序扩展,以防万一。谢谢。</p>

<p><strong>更新:这是自定义类 init 和 refreshData 的代码</strong></p>

<pre><code>- (instancetype)init {
    self = ;
    if (!self)
      return nil;
    return self;
}

- (BOOL)refreshData {
    return YES;
}
</code></pre>

<p><strong>更新 2:</strong>我创建了一个空白的工作项目并将确切的文件复制粘贴到我的原始项目中(因为它是大型 iOS 应用程序的 iMessage 扩展)。事实证明,即使在我清理了项目并更改了 UITableView 委托(delegate)以提供不同的文本之后,Xcode 仍在运行应用程序的旧版本。
<a href="/image/e14It.png" rel="noreferrer noopener nofollow"><img src="/image/e14It.png" alt="more"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我过去为同一个项目创建了一个消息扩展,并删除了目标,同时将文件保留在项目中。当我将 Messages Extension 重新添加到项目中时,Xcode 继续运行旧版本的应用程序。
我通过以下方式解决了 Xcode 运行旧版本应用程序的问题:</p>

<ol>
<li>全部清除</li>
<li>从项目中删除消息扩展目标</li>
<li>将现有的消息扩展代码备份到项目之外的目录。然后从项目中删除 Messages 应用组和目录。</li>
<li>从项目中删除 Messages Extension 构建方案。</li>
<li>删除项目派生数据目录。</li>
<li>重启 Xcode,在项目中新建 Messages Extension 目标,并导入保存的代码。 </li>
</ol></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 未调用 ObjC 类方法。 GDB玩游戏?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39887080/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39887080/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 未调用 ObjC 类方法。 GDB玩游戏?