2012-04-19 137 views
1

代码不能运行 错误:太多的参数的方法调用,预计1,有2个cocoa:如何将整数类型转换为字符串类型?

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类型转换为字符串类型?我能做什么?

回答

9

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

改变这一点:

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

这样:

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