返回stringfromdate方法

Mat*_*ich 1 iphone cocoa-touch ios ios5

所以这里有一些我遇到问题的代码:

//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];
Run Code Online (Sandbox Code Playgroud)

给出的错误是:"方法调用的参数太多,预期为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];
Run Code Online (Sandbox Code Playgroud)

给出错误:"接口类型无法静态分配"

坦率地说,我不知道为什么它给了我这个错误...一些帮助将不胜感激.它可能只是一些小东西,我只是因为某种原因没有看到= /

欢呼,马特

Ila*_*ian 5

而不是线

[self.startDate setText:@"You started on: %@", dateForOutput];
Run Code Online (Sandbox Code Playgroud)

在您提供的第一个代码块中,尝试以下行

[self.startDate setText:[NSString stringWithFormat:@"You started on: %@", dateForOutput]];
Run Code Online (Sandbox Code Playgroud)

但最好再接受第二个陈述,

NSString *foobar = [NSString stringWithFormat:@"You started on: %@", dateForOutput];
Run Code Online (Sandbox Code Playgroud)