2011-11-02 126 views

回答

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

而在你MyViewController類:

.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" 
    } 
1

我不相信你可以,但當然你可以添加相關的屬性或方法到你的ViewController類,並在推送之前使用它們。

+1

由downvotes困惑,因爲我寫的正是接受的答案在代碼中所做的...... – Clafou

0

不可以。您可能會將NSBundle等同於Android的Bundle,但它們不相關,也不執行類似任務。 Clafou建議通過方法和屬性傳遞數據是正確的。

相關問題