Eri*_*ric 5 pointers objective-c ios
好的,我正在努力解决这个问题.我已经搜索了过去的一小时,我不知道我做错了什么.我正在尝试获取发送者的currentTitle,然后将其转换为整数,以便我可以在调用列表中使用它.
NSString *str = [sender currentTitle];
NSInteger *nt = [str integerValue]; // this is where the error appears //
NSString *nextScreen = [NSString stringWithFormat:@"Screen_%@.jpg", [screenList objectAtIndex:nt]];
Run Code Online (Sandbox Code Playgroud)
我认为它与之相关 [str integerValue]没有正确使用,但我找不到一个有效的例子.
谢谢!
Jac*_*kin 16
让我们分析一下错误信息:
Initialization(NSInteger nt)*从整数([str integerValue])中生成指针()而不进行强制转换.
这意味着你正在试图非指针型(的变量分配[str integerValue],它返回一个NSInteger),以可变的指针类型.(NSInteger *).
摆脱*后NSInteger,你应该没问题:
NSString *str = [sender currentTitle];
NSInteger nt = [str integerValue]; // this is where the error appears //
NSString *nextScreen = [NSString stringWithFormat:@"Screen_%@.jpg", [screenList objectAtIndex:nt]];
Run Code Online (Sandbox Code Playgroud)
NSInteger 是机器相关的整数数据类型的类型包装器,其定义如下:
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24459 次 |
| 最近记录: |