iphone - 倒计时应用程序给出预期的 "]"错误

标签 iphone objective-c ios ios5

我正在为 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/

相关文章:

iphone - 如何处理编译器优化问题

iphone - UITableView 上的圆角

iphone - 如何让外语文本在 UITextView 中正确显示

ios - 在运行时在 iOS 上添加框架

iPhone:语音识别在 IOS SDK 中可用吗?

iphone - 将 URL(作为字符串)添加到数组时出现问题

objective-c - didSelectRowAtIndexPath 任意调用

iphone - 如何确定滚动 UITableView 的触摸次数

ios - 从 Objective-C 文件调用 UIImageView 的 Swift 扩展中的方法

ios - NSString 有一些属性值 用 & 符号如何获取该属性值