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.