我有一个应用程序,它有一个名为 MainViewController 的第一个视图控制器,它有点像秒表,当我点击完成时,它会显示一个 UIAlertView 推送另一个视图控制器 EndViewController,它显示秒表运行了多长时间以及它暂停了多长时间. 我收到以下错误:
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'
谁能指出你有什么问题?
这是我的代码:
主视图控制器.h:
#import "EndViewController.h"
@interface MainViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UIAlertViewDelegate>
@property (strong, nonatomic) IBOutlet UILabel *out;
@property (strong, nonatomic) IBOutlet UILabel *in;
@end
主视图控制器.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