對不起,發佈了這個消息,但我一直在摔跤了一段時間,我一直在嘗試使用timeIntervalSinceDate
,但它不行爲。這是M檔:objective c error「沒有可見的@interface for'NSString'聲明選擇器'timeIntervalSinceDate:'」
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController //warning: Method definition for 'timeIntervalSinceDate:' not found
-(IBAction) setButtonTapped:(id)sender {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date ];
NSLog(@"Set button tapped : %@", dateTimeString);
NSDate* currentDate = [NSDate date];
NSTimeInterval secs = [dateTimeString timeIntervalSinceDate:currentDate]; //error: No visible @interface for 'NSString' declares the selector 'timeIntervalSinceDate:’
NSLog(@"Seconds %f", secs);
[self scheduleLocalNotificationWithDate: dateTimePicker.date];
[self presentMessage:@"succesfully set!"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
,這是.h文件:
#import <UIKit/UIKit.h>
#import <AvFoundation/AVFoundation.h>
@interface ViewController : UIViewController <AVAudioPlayerDelegate>
{
IBOutlet UIDatePicker *dateTimePicker;
}
- (NSTimeInterval)timeIntervalSinceDate:dateTimePicker;
-(IBAction) setButtonTapped:(id)sender;
@end
也將方法是什麼timeIntervalSinceDate
?我無法找到任何信息,因爲我對此很陌生,因此確定如何爲自己解決問題。
感謝