我正在为 iPhone 和 iPad 构建我的第一个应用程序,它是一个简单的应用程序,可以倒计时给定的月、日、小时、分钟和秒。
修复了几个错误后,出现了以下错误:
Expected "]"
代码如下:
#import "ViewController.h"
@implementation ViewController
-(void)updateLabel {
NSCalendar *calender = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int units = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [calender components:units fromDate:[NSDate date] toDate:destinationDate options:0 ];
[dateLabel setText:[[NSString stringWithFormat:@"%d%c %d%c %d%c %d%c %d%c" , [components month], 'm' [components day], 'd' , [components hour], 'h' , [components minute], 'm' , [components second], 's' ]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
destinationDate = [[NSDate dateWithTimeIntervalSince1970:1325153549] retain];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector (updateLabel) userInfo:nil repeats:YES];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
最佳答案
[dateLabel setText:[[NSString stringWithFormat:@"%d%c %d%c %d%c %d%c %d%c" , [components month], 'm' [components day], 'd' , [components hour], 'h' , [components minute], 'm' , [components second], 's' ]];
不平衡的括号?
关于iphone - 倒计时应用程序给出预期的 "]"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8518088/