gpt4 book ai didi

ios - 将 NSString 更改为 int 值?

转载 作者:IT王子 更新时间:2023-10-29 08:01:52 24 4
gpt4 key购买 nike

由于此代码第一行的错误,我在尝试运行此测试时遇到了问题:

Incompatible pointer to integer conversion initializing 'int' with an expression of type 'NSString *'

- (IBAction)Button:(id)sender 
{
int x = TramNumber.text;
if (x < 9)
{
Tramresult.text = [NSString stringWithFormat:@"lol"];
}
else
{
NSLog (@"x is less than 9!");
}
}
@end

请帮忙。如果有帮助,我在 iOS 上运行 xCode 5.1.1。

最佳答案

你代表的 NSString 值是错误的。

使用此代码示例来解决您的问题:

int x = [TramNumber.text intValue];

表示文本字段中的 int 值。

关于ios - 将 NSString 更改为 int 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26336373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com