У меня есть приложение, в котором есть первый контроллер представлений, называемый 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'
Может ли кто-нибудь указать мне, что случилось?
Heres мой код:
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
Попробуйте выполнить регистрацию segue.destinationViewController в prepareForSegue и посмотреть, что это дает вам. – rdelmar
Это может помочь ... http://stackoverflow.com/questions/6563597/iphone-difference-between-topviewcontroller-and-other-forms – SomeSillyName