【发布时间】:2015-09-29 21:20:23
【问题描述】:
我的应用程序出现此错误:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<ViewController: 0x17e60c10>) has no segue with identifier 'dateTimeString''。代码是这样的:
ViewController.m
-(IBAction) alarmSetButtonTapped:(id)sender {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
[dateFormatter setDateFormat:@"dd:MM:YYYY:ss:mm:hh"];
NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date ];
NSLog( @"Alarm Set : %@", dateTimeString );
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd:MM:YYYY:ss:mm:hh"];
NSDate *dateTimeSeconds = [[NSDate alloc] init];
dateTimeSeconds = [dateFormatter1 dateFromString:dateTimeString];
NSTimeInterval seconds = [[NSDate date] timeIntervalSinceDate:dateTimePicker.date];
NSLog(@"seconds %.f", seconds);
NSString *path = [NSString stringWithFormat:@"%@/Alarm-Clock.m4a", [[NSBundle mainBundle] resourcePath]];
NSURL *soundUrl = [NSURL fileURLWithPath:path];
_alarmPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
[_alarmPlayer playAtTime: _alarmPlayer.deviceCurrentTime + seconds];
NSLog( @"Alarm Set button tapped : %@", dateTimeString );
[self scheduleLocalNotificationWithDate: dateTimePicker.date];
[self performSegueWithIdentifier:@"dateTimeStringSegue" sender: nil];
[self presentMessage:(@"Alarm succesfully set for %@",dateTimeString)];
}
-(IBAction)alarmCancelButtonTapped:(id)sender {
NSLog( @"Alarm Cancel button tapped");
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[self presentMessage:@"Alarm Canceled Lazy Pants!"];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
ViewController3 *tvc = segue.destinationViewController;
NSLog(@"prepareForSegue: %@", segue.identifier);
if ([[segue identifier] isEqualToString:@"dateTimeStringSegue"])
{
tvc.dateTimeString = (@"%@",_dateTimeString);
NSLog(@"Segue");
}
}
ViewController.h
@interface ViewController : UIViewController <AVAudioPlayerDelegate>
{
IBOutlet UIDatePicker *dateTimePicker;
}
@property NSInteger numberOfLoops;
@property(readonly) NSTimeInterval deviceCurrentTime;
@property (strong, nonatomic) AVAudioPlayer *alarmPlayer;
@property (strong, nonatomic) NSString *dateTimeString;
- (NSTimeInterval)timeIntervalSinceDate:dateTimePicker;
-(void) presentMessage: (NSString *) message;
-(void) scheduleLocalNotificationWithDate: (NSDate *) fireDate;
-(IBAction) alarmSetButtonTapped:(id)sender;
-(IBAction) alarmCancelButtonTapped:(id)sender;
- (BOOL)playAtTime:(NSTimeInterval)time;
@end
SegueDestination.h
#import "ViewController.h"
@interface ViewController3 : UIViewController
@property(nonatomic, readonly) NSUInteger tapCount;
@property NSInteger numberOfLoops;
@property(readonly) NSTimeInterval deviceCurrentTime;
@property (strong, nonatomic) AVAudioPlayer *alarmPlayer;
@property (strong, nonatomic) NSString *dateTimeString;
@property (strong, nonatomic) IBOutlet UILabel *dateTimePicker;
- (NSTimeInterval)timeIntervalSinceDate:dateTimePicker;
- (BOOL)playAtTime:(NSTimeInterval)time;
- (IBAction)iconsBtn:(id)sender;
@end
SegueDestination.m
#import "ViewController.h"
@interface ViewController3 ()
{
AVAudioPlayer *_alarmPlayer;
}
@end
@implementation ViewController3
- (void)viewDidLoad {
[super viewDidLoad]
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"wwv5.jpg"]];
}
- (void) buttonTouchDownRepeat:(id)sender event:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if(touch.tapCount == 3) {
NSLog(@"Twice");
}
else
NSLog(@"UGHHHHH");
}
- (IBAction)iconsBtn:(id)sender {
}
我正在尝试访问我的2nd ViewController 中的dateTimeString,但是每当我单击应该发送它的按钮时,我的应用程序都会因该错误而终止。这是我第一次尝试使用 segue,但我对它不太满意。对这个错误进行排序后,我可以在2nd ViewController 中调用dateTimeString 并获取在1st ViewController 中设置的值吗?
谢谢!
编辑:我已经在情节提要中完成了标识符。
【问题讨论】:
标签: ios objective-c uiviewcontroller segue