我制作了一个非常基本的 iOS 应用程序,它在 viewDidLoad 的标签中显示时间。我在这行代码中收到预期标识符错误:
NSString *myTime = [myDateFormatter stringFromDate:[*myDate]];
这是 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
做了一些补充。代码已编译,但现在我收到 Thread 1:SIGABRT 错误。该应用程序未在模拟器上加载,并且出现错误。这是在 main() 中给出错误的代码行:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
是的,我没有链接。它现在工作。谢谢你们!