iOS - passing data to pushed viewcontroller

百般思念 提交于 2019-12-05 00:04:09

问题


When pushing a viewcontroller, how do I pass data long with it as well (such as "asdf":123)? Are you supposed to addObjects to a NSBundle?


回答1:


MyViewController * myVC = [[MyViewController alloc] initWithNibName:nil bundle:nil];
myVC.someProperty = someValue;    // Pass your data here
[self.navigationController pushViewController:myVC animated:YES];

And in your MyViewController class :

.h

@interface MyViewController : UIViewController
@property (nonatomic, strong) NSString * someProperty;
@end

.m

@implementation MyViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        // your data has been set
        // self.someProperty is equal to "some value"
    }



回答2:


I don't believe you can, but of course you can add relevant properties or methods to your ViewController class and use these prior to pushing it.




回答3:


No. You may be equating NSBundle with Android's Bundle, but they are not related and do not perform similar tasks. Clafou is correct to suggest passing data via methods and properties.



来源:https://stackoverflow.com/questions/7979976/ios-passing-data-to-pushed-viewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!