您好,我正在尝试将 indexvalue 从我的父 View 传递到我的 subview ,如下所示 //main.m
SubViewController *subViewController = [[SubViewController alloc] init];
subViewController.parentViewSelectedIndexPath = indexPath;
但是,当我尝试检查该值是否已像这样传递给 subview 时
//sub.m
- (void)viewDidLoad
{
//
NSLog(@"%@", parentViewSelectedIndexPath);
//
侧倾 子.h
//
@interface VehicleResultViewController : UITableViewController {
//
NSIndexPath *parentViewSelectedIndexPath;
//
@property (nonatomic, retain) NSIndexPath *parentViewSelectedIndexPath;
//
@end
//Answer
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.
它在控制台上打印 (null).. 我做错了吗?
添加一些 NSLog
来确定调用顺序,@Kevin 指出 viewDidLoad
可能会在设置属性之前被调用。
另外,如果 indexPath
总是在 subViewController
被实例化时设置,最好使用 indexPath
作为参数来创建您自己的指定初始化程序.如果@Kevin 给出了这个答案。
关于iphone - 将 IndexPath 传递给 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7640140/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |