我有一個應用程序,它有一個叫做MainViewController的第一個視圖控制器,它不像秒錶,當我點擊完成時,它顯示一個UIAlertView推送另一個視圖控制器EndViewController,它顯示秒錶運行了多久,暫停了多久。我收到以下錯誤:iOS:在兩個視圖控制器之間共享數據時遇到問題
My Point[851:c07] -[EndViewController topViewController]: unrecognized selector sent to instance 0x754db60
My Point[851:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[EndViewController topViewController]: unrecognized selector sent to instance 0x754db60'
任何人都可以指出我對什麼是錯?
繼承人我的代碼:
MainViewController.h:
#import "EndViewController.h"
@interface MainViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UIAlertViewDelegate>
@property (strong, nonatomic) IBOutlet UILabel *out;
@property (strong, nonatomic) IBOutlet UILabel *in;
@end
MainViewController.m:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"endtask"]){
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
EndViewController *controller = (EndViewController *)navController.topViewController;
controller.timeIn.text=_in.text;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
_alert = [[UIAlertView alloc] initWithTitle:@"Are you sure?"
message:nil
delegate:self
cancelButtonTitle:@"NO"
otherButtonTitles:@"YES", nil];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
//do nothing
}
else if (buttonIndex == 1) {
[self performSegueWithIdentifier:@"endtask" sender:self];
}}
- (IBAction)endButton:(UIButton *)sender {
[_alert show];
}
- (IBAction)endButton:(UIButton *)sender {
[_alert show];
}
EndViewController.h:
@interface EndViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *timeIn;
@end
嘗試在prepareForSegue中記錄segue.destinationViewController,並查看給了你什麼。 – rdelmar
這可能會有所幫助... http://stackoverflow.com/questions/6563597/iphone-difference-between-topviewcontroller-and-other-forms – SomeSillyName