初始化使得整数指针没有强制转换

初始化使得整数指针没有强制转换

本文介绍了初始化使得整数指针没有强制转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在努力解决这个问题。我已经搜索了过去的一小时,我不知道我做错了什么。我正在尝试获取发送者的currentTitle,然后将其转换为整数,以便我可以在列表调用中使用它。

Okay, I am having a hard time with this. I've searched for the past hour on it and I don't get what I am doing wrong. I'm trying to take the currentTitle of a sender, then convert it to an integer so I can use it in a call to list.

NSString *str = [sender currentTitle];
NSInteger *nt = [str integerValue]; // this is where the error appears //
NSString *nextScreen = [NSString stringWithFormat:@"Screen_%@.jpg", [screenList objectAtIndex:nt]];

我认为这是 [str integerValue] 位没有正确使用,但我找不到一个有效的例子。

I assume it's something with the [str integerValue] bit not being properly used, but I can't find an example that works.

谢谢!

推荐答案

让我们分析错误信息:

初始化( NSInteger nt )在没有强制转换的情况下从整数( [str integerValue] )生成指针( * )。 / em>

Initialization (NSInteger nt) makes pointer (*) from integer ([str integerValue]) without a cast.

这意味着您正在尝试分配非指针类型的变量( [str integerValue] ,它返回 NSInteger )到 指针类型的变量。 ( NSInteger * )。

This means that you are trying to assign a variable of non-pointer type ([str integerValue], which returns an NSInteger) to a variable of pointer type. (NSInteger *).

摆脱 * NSInteger 后你应该没问题:

Get rid of the * after NSInteger and you should be okay:

NSString *str = [sender currentTitle];
NSInteger nt = [str integerValue]; // this is where the error appears //
NSString *nextScreen = [NSString stringWithFormat:@"Screen_%@.jpg", [screenList objectAtIndex:nt]];

是机器相关的类型包装器积分数据类型,定义如下:

NSInteger is a type wrapper for the machine-dependent integral data type, which is defined like so:

#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

这篇关于初始化使得整数指针没有强制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 20:06