菜鸟教程小白 发表于 2022-12-11 20:19:02

iphone - 将 IndexPath 传递给 subview


                                            <p><p>您好,我正在尝试将 indexvalue 从我的父 View 传递到我的 subview ,如下所示
//main.m</p>

<pre><code>SubViewController *subViewController = [ init];
subViewController.parentViewSelectedIndexPath = indexPath;
</code></pre>

<p>但是,当我尝试检查该值是否已像这样传递给 subview 时</p>

<p>//sub.m</p>

<pre><code>- (void)viewDidLoad
{
//
NSLog(@&#34;%@&#34;, parentViewSelectedIndexPath);
//
</code></pre>

<p>侧倾
子.h</p>

<pre><code>//
@interface VehicleResultViewController : UITableViewController {
//
NSIndexPath *parentViewSelectedIndexPath;
//
@property (nonatomic, retain) NSIndexPath *parentViewSelectedIndexPath;
//
@end
</code></pre>

<blockquote>
<p>//Answer</p>

<p>subview loads before it gets the indexpath being passed to is.. so I
had to use a method that is executed later
i.s.(didselectrowatindexpath) this printed out the correct indexpath
that was sent to it from the main view.</p>
</blockquote>

<p>它在控制台上打印 (null).. 我做错了吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>添加一些 <code>NSLog</code> 来确定调用顺序,@Kevin 指出 <code>viewDidLoad</code> 可能会在设置属性之前被调用。</p>

<p>另外,如果 <code>indexPath</code> 总是在 <code>subViewController</code> 被实例化时设置,最好使用 <code>indexPath</code> 作为参数来创建您自己的指定初始化程序.如果@Kevin 给出了这个答案。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 将 IndexPath 传递给 subview ,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/7640140/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/7640140/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 将 IndexPath 传递给 subview