2011-12-15 5 views
0

Я строю свое первое приложение для iPhone и iPad, это простое приложение, которое учитывает данные, относящиеся к данному месяцу, дате, часу, минуте и секунде.Count Down Application giving Ожидаемая ошибка «]»

После фиксации несколько ошибок это наткнулся на следующую ошибку:

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 
+0

Вы можете разместить строку кода, где точное e rror показано ... –

+0

, вы, вероятно, пропустили какой-либо] или добавили еще один, какая строка кода дает эту ошибку? –

+0

Кажется, что строка, начинающаяся с '[dateLabel setText:' в 'updateLabel', отсутствует' '' 'у вас в основном' [dateLabel setText: [[...]]; ' – luastoned

ответ

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

несбалансированные скобки?

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

Вы делаете открыты три [в первой части, прежде чем 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' ]]; 
0

Эта строка содержит синтаксические ошибки:

[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.

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

кажется, что вы забыли запятую здесь

'm' [components day] 

Надеется, что это помогает

Edit:

И есть 1 "[" слишком многие до NSString