cocoa:Integer类型如何转换为字符串类型?

时间:2012-04-19 07:16:34

标签: objective-c xcode macos cocoa

代码无法运行 错误:方法调用的参数太多,预期为1,有2个

NSDate *nows =[NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [gregorian components:(NSHourCalendarUnit  | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:nows];
NSInteger hour = [dateComponents hour];
NSInteger minute = [dateComponents minute];
NSInteger second = [dateComponents second];
NSInteger month=[dateComponents month];
NSInteger day=[dateComponents day];
NSLog(@"%lu",day);    

statusItem.image=[NSImage imageNamed:@"status%lu.png",day];

[gregorian release];

enter image description here

是不是试图将Integer类型转换为字符串类型?我该怎么办?

1 个答案:

答案 0 :(得分:9)

NSImage的“imageNamed”方法对格式字符串一无所知。

改变这个:

statusItem.image=[NSImage imageNamed:@"status%lu.png",day];

到此:

statusItem.image=[NSImage imageNamed:[NSString stringWithFormat: @"status%lu.png",day]];