传递'objectAtIndex:'的参数1使得没有强制转换的指针产生整数

时间:2013-06-14 06:08:45

标签: iphone

当我从选择器中选择数据时,应用程序崩溃。

NSString *labl=[NSString stringWithFormat:@"%d",[self.datePicker selectedRowInComponent:0]];
NSString *strPrintRepeat = (NSString *)[years objectAtIndex:labl];

2 个答案:

答案 0 :(得分:2)

您知道您正在将NSString传递给objectAtIndex [years objectAtIndex:labl];。这里labl是一个不是integer值的字符串。所以你需要将这个字符串转换成int值或者这样做。

NSString *strPrintRepeat = (NSString *)[years objectAtIndex:[self.datePicker selectedRowInComponent:0]];

答案 1 :(得分:1)

尝试下面的代码行: -

objectAtIndex在Array.h文件中具有NSUInteger参数define方法: -

enter image description here

请研究苹果提供的Doc: -

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html

你可以像下面那样使用你的方法: -

NSString *strPrintRepeat = (NSString *)[years objectAtIndex:[labl intValue]];