Iphone 倒计时应用程序给出预期的“倒计时”&引用;错误

Iphone 倒计时应用程序给出预期的“倒计时”&引用;错误,iphone,objective-c,ios,ios5,Iphone,Objective C,Ios,Ios5,我正在为iPhone和iPad构建我的第一个应用程序,它是一个简单的应用程序,可以倒计时到给定的月、日、小时、分钟和秒 在修复了几个错误后,出现了以下错误: 应为“]” 代码如下: #import "ViewController.h" @implementation ViewController -(void)updateLabel { NSCalendar *calender = [[NSCalendar alloc] initWithCalendarIdentifier:NSGreg

我正在为iPhone和iPad构建我的第一个应用程序,它是一个简单的应用程序,可以倒计时到给定的月、日、小时、分钟和秒

在修复了几个错误后,出现了以下错误:

应为“]”

代码如下:

#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' ]]; 
您确实在
NSString
之前的第一部分中打开了三个[但最后只关闭了其中的两个]

[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' ]]; 

我想是这个吧

[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' ]]; 
您确实在
NSString
之前的第一部分中打开了三个[但最后只关闭了其中的两个]

[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' ]]; 

此行包含语法错误:

[dateLabel setText:[NSString stringWithFormat:@"%d%@  %d%@  %d%@  %d%@  %d%@" , [components month], @"m", [components day], @"d" , [components hour], @"h" , [components minute], @"m" , [components second], @"s"]]; 

您缺少一个逗号,并且在NSString前面有太多的左括号。

此行包含语法错误:

[dateLabel setText:[NSString stringWithFormat:@"%d%@  %d%@  %d%@  %d%@  %d%@" , [components month], @"m", [components day], @"d" , [components hour], @"h" , [components minute], @"m" , [components second], @"s"]]; 

您丢失了一个逗号,并且在NSString之前有太多的左括号。

错误具体在哪里?我想可能在这里:

[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' ]]; 
你好像忘了一个逗号

'm' [components day]
希望能有帮助

编辑:


NSString前面有1“[”个错误,错误在哪里?我想可能在这里:

[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' ]]; 
你好像忘了一个逗号

'm' [components day]
希望能有帮助

编辑:


NSString前面有1“[”太多了

你能在显示确切错误的代码行上贴出来吗……你可能遗漏了任何一行]或者添加了另一行,哪一行代码会出现这个错误?似乎
更新标签
中以
[dateLabel setText:
开头的那一行缺少了
]
你基本上拥有的
[dateLabel setText:[[…]];
您可以在显示确切错误的代码行中发布代码…您可能缺少任何代码]或添加另一行代码,哪一行代码会出现此错误?似乎
updateLabel
中以
[dateLabel setText:
开头的行缺少
]
您基本上有
[dateLabel setText:[…];