菜鸟教程小白 发表于 2022-12-13 00:22:26

iphone - 在选择 UITableViewCell 时导航到新的 DetailViewController


                                            <p><p>问题:在选择特定的 <code>uitableviewcell</code> 时,应该打开一个新的 <code>DetailViewController</code>。我已经在 <code>didSelectRowAtIndexPath</code> 中编写了代码,但是当我单击单元格时,它向我显示运行时错误。</p>

<p>我尝试使用 <code>;</code> 调用,但是当我这样做时,我的 ViewController 没有打开。</p>

<p>我尝试的另一种方法是 <code>;</code>.</p>

<p>我在检查器中有“JacketDetails”的segued 中指定的标识符,但在这里我得到一个运行yime 错误。我已经从 <code>UITABLEVIEWCELL</code>HookSegue 到 <code>VIEWCONTROLLER</code>。</p>

<p>当我点击行 <code>JacketDetailViewController</code> 应该是打开的。我已经创建了类 <code>JacketDetailViewController</code> 并且对于 <code>New ViewController</code> 我已经在检查器中为此设置了类。</p>

<p>我不知道为什么它没有显示 segue ,我已经在检查器中给出了标识符并正确地从 <code>tableviewcell</code>Hook 到新的 ViewController 。</p>

<p>在 <code>JacketDetailViewController</code> 我想显示夹克列表。目前它是空白的<code>ViewController</code>。</p>

<p>我的代码如下。你能提出一个解决方案吗?我是这个领域的自学初学者。我可能犯了一些小错误。我用谷歌搜索了我的问题并试图解决它,但我已经在这里停留了几天。</p>

<pre><code>TshirtDetailViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.

    ;

    JacketDetailController *jacket =[init];

    NSInteger index =indexPath.row;

    NSLog(@&#34;Row:%d&#34;,index);


    NSString *titleString = [ initWithFormat:];


    NSLog(@&#34;%@&#34;,titleString);
    jacket.title=titleString;


    // ...
    // Pass the selected object to the new view controller.

    ;


//;

}


@end
</code></pre>

<p>控制台错误:</p>

<pre><code>2013-01-07 10:52:21.020 KidsShopee *** Terminating app due to uncaught exception &#39;NSInvalidArgumentException&#39;, reason: &#39;Receiver (&lt;UINavigationController: 0x6a5fac0&gt;) has no segue with identifier &#39;JacketDetails&#39;&#39;

*** First throw call stack:

(0x13bf052 0x1550d0a 0xdd24b 0x3e8e 0xa671d 0xa6952 0x92e86d 0x1393966 0x1393407 0x12f67c0 0x12f5db4 0x12f5ccb 0x12a8879 0x12a893e 0x16a9b 0x1b08 0x1a65 0x1)
terminate called throwing an exception(gdb)
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>尝试使用这些行打开 View :</p>

<pre><code>    YoutubeViewController *objYoutubeViewController = [initWithNibName:@&#34;YoutubeViewController&#34; bundle:];
    ;
    ;
</code></pre>

<p>代替 YoutubeViewController 给你的 ViewController 类名并更改这些行</p>

<p>根据您的情况并检查。如果您使用 Storyboard ,请尝试如下操作:</p>

<pre><code>UIStoryboard *mainStoryboard = ;
bookmarkViewController *myVC = (bookmarkViewController *)
;
</code></pre>

<p>代替bookmarkViewController 给出您的 Controller 名称并检查。在拖放 View 中</p>

<p>主 Storyboard中的 Controller 给出正确的类名,如下图所示:<img src="/image/Fb0fi.png" alt="enter image description here"/> </p>

<p>代替我的 bookmarkViewController 名称,给出您要打开的 ViewController 名称。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 在选择 UITableViewCell 时导航到新的 DetailViewController,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/14190370/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/14190370/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 在选择 UITableViewCell 时导航到新的 DetailViewController