我做了一個非常基本的iOS應用程序,它在viewDidLoad上的標籤上顯示時間。 我在這行代碼得到一個期望的標識符錯誤:iOS應用程序中的「預期標識符」錯誤
NSString *myTime = [myDateFormatter stringFromDate:[*myDate]];
Here'e的ViewController.m文件:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
@synthesize timeLabel;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSDateFormatter *myDateFormatter = [[NSDateFormatter alloc] init];
[myDateFormatter setDateFormat:@"HH:mm a"];
NSDate *myDate = [[NSDate alloc] init];
NSString *myTime = [myDateFormatter stringFromDate:myDate];
[timeLabel setText : myTime];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
提出了一些補充。代碼編譯,但現在我得到一個線程1:SIGABRT錯誤。 該應用程序無法加載模擬器,並且出現錯誤。 這裏的代碼是給錯誤在main()行:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
是啊,我也沒聯繫起來。它的工作現在。謝謝你們!
不要只是刪除*,還要刪除[]周圍的myDate。 – amb
我只是測試你的代碼與NSString * myTime = [myDateFormatter stringFromDate:myDate];它給了我時間。 –
你在界面生成器中鏈接了timeLabel嗎?這段代碼也適用於我。 – AMAN77