我已經知道如何在UIViewController
之間傳遞值或變量。事實上,我在2 + 2 UIViewController
之間有2次轉換,但是我有一個沒有這樣做的轉換。不理解如何在ViewControllers之間傳遞值
我試圖複製一切,但這個似乎並沒有工作。
這是我如何處理點擊傳遞到另一個UIViewController
:
-(void)launchProfile:(int) option {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Profile" bundle:nil];
ProfileControllerViewController *vc = [sb instantiateViewControllerWithIdentifier:@"ProfileControllerViewController"];
[vc passValue:_user];
[vc passOption:option];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
}
這是我ProfileControllerViewController.h
:
@interface ProfileControllerViewController : UIViewController
-(void)passValue:(NSDictionary*)user;
-(void)passOption:(int)option;
@property (nonatomic , strong) NSDictionary* user;
// ...
@end
This is my
ProfileControllerViewController.m`(在這裏我實現該功能的一部分
@implementation ProfileControllerViewController
int optionSelected = -1;
const int optionChanges = 0;
const int optionComments = 1;
-(void)passOption:(int) option {
optionSelected = option;
}
- (void) passValue:(NSDictionary *)user_ {
_user = user_;
}
// ...
@end
何時它執行所passValue
或passOption
誤差爲:
2015年6月27日12:31:51.616 Ch4nge.me [41958:1907763] viewDidAppear 2015年6月27日12:31:56.041 Ch4nge.me [41958: 1907763] Interface Builder文件中的未知類_TtC31ProfileControllerViewController31ProfileControllerViewController。 2015-06-27 12:31:57.102 Ch4nge.me [41958:1907763] - [UIViewController passUser:]:無法識別的選擇器發送到實例0x7fb505412c00 2015-06-27 12:31:57.107 Ch4nge.me [41958:1907763 ***終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因是: ' - [UIViewController中passUser:]:無法識別的選擇發送到實例0x7fb505412c00'
可能是錯誤???
非常感謝您提前。
從日誌中,您似乎忘記在故事板中設置類。請檢查它 – Leo
也許考慮在'ProfileControllerViewController'中定義屬性,然後在launchProfile:中設置它們。它基本上是你現在正在做的同樣的事情,但一點點清潔。 – JaredH