我是Objective-c和stackOverflow的新手。 :)無法在iOS中的視圖控制器之間傳輸數據
我已經創建了2個視圖控制器通過稱爲「showDetailSegue」的segue連接。
在LPLviewcontroller1中,我有一個句子屬性,我用它來設置LPLviewcontroller1中textview中的文本,並且我想用segue在LPLviewcontroller中設置句子屬性的值。此外,我在LPLviewcontroller上有一個可以執行「showDetailSegue」的按鈕。
但是,程序停止在
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([LPLAppDelegate class]));
(program breaks here)
}
}
系統日誌
2014-06-25 16:49:43.199 test[6322:60b] -[LPLViewController button:]: unrecognized selector sent to instance 0x8d43f30
2014-06-25 16:49:43.204 test[6322:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LPLViewController button:]: unrecognized selector sent to instance 0x8d43f30'
下面是LPLviewController.m
#import "LPLViewController.h"
#import "LPLViewController1.h"
@interface LPLViewController()
@end
@implementation LPLViewController
- (IBAction)press:(id)sender {
[self performSegueWithIdentifier:@"showDetailSegue" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"showDetailSegue"]){
LPLViewController1 *controller = (LPLViewController1 *)segue.destinationViewController;
controller.sentence = @"dfjlasdkfjlskdfjlksdjflkadsjf";
}
}
@end
下面是LPLviewController1.m
#import "LPLViewController1.h"
@implementation LPLViewController1
-(void) viewDidLoad
{
_text.text = _sentence;
}
@end
你如何定義按鈕的事件? – DaSilva