2012-01-02 97 views
1

所以这里是我遇到的麻烦一些代码:返回stringfromdate方法

//format the date to a string for echoing it 
    NSDateFormatter* formattedDate = [[NSDateFormatter alloc] init]; 
    [formattedDate setDateStyle:NSDateFormatterLongStyle]; //now myFormatted is set to a long style 
    NSString* dateForOutput = [formattedDate stringFromDate:self.datePickerOutlet.date]; 
    //also now need to set the "you began on" text to the newly chosen date 
    [self.startDate setText:@"You started on: %@", dateForOutput]; 

所给出的错误:“参数太多方法调用,预计1,有2个”

我不明白为什么它说我想通过两种方法。 我试图做的情况下,下面我太傻了,但它仍然给了我一个错误:“接口类型不能是静态分配”

坦白说,我不知道为什么它是:给

//format the date to a string for echoing it 
NSDateFormatter* formattedDate = [[NSDateFormatter alloc] init]; 
[formattedDate setDateStyle:NSDateFormatterLongStyle]; //now myFormatted is set to a long style 
NSString* dateForOutput = [formattedDate stringFromDate:self.datePickerOutlet.date]; 
//also now need to set the "you began on" text to the newly chosen date 
NSString *foobar = @"You started on: %@", dateForOutput; 
[self.startDate setText:foobar]; 

错误给我这个错误...一些帮助将不胜感激。 这可能只是我只是没有看到由于某些原因小东西=/

欢呼声, 马特

+0

没有u表示日期选择器和创建的UILabel属性..? – userar 2012-01-02 06:30:19

回答

5

而是在一个代码块的行

[self.startDate setText:@"You started on: %@", dateForOutput]; 

的你给,请尝试以下行

[self.startDate setText:[NSString stringWithFormat:@"You started on: %@", dateForOutput]]; 

但最好是去与第二陈述,

NSString *foobar = [NSString stringWithFormat:@"You started on: %@", dateForOutput]; 
+0

就是这样!非常感谢你! – 2012-01-02 06:31:02

+0

不客气! – Ilanchezhian 2012-01-02 06:32:32

0

你正在做的事情错误的方式

你应该做的事情,这样

NSDate* myDate=[NSDate new]; 

NSDateFormatter* formattedDate = [[NSDateFormatter alloc] init]; 

[formattedDate setDateStyle:NSDateFormatterLongStyle]; 

//现在myFormatted被设置为长款

//这里我刚刚通过当前日期

NSString* dateForOutput = [formattedDate stringFromDate:myDate]; 

//also now need to set the "you began on" text to the newly chosen date 

NSString *foobar = @"You started on:"; 

//否W使您可以将字符串

//这是你可以将字符串的方式..

foobar= [foobar stringByAppendingFormat:@"%@",dateForOutput]; 

[self.startDate setText:foobar];