gpt4 book ai didi

objective-c - 关于从整数转换指针而不进行强制转换的警告-需要说明

转载 作者:行者123 更新时间:2023-12-01 17:35:02 24 4
gpt4 key购买 nike

我有这个代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic
NSLog(@"didSelectRowAtIndexPath");

//The hud will dispable all input on the view
HUD = [[MBProgressHUD alloc] initWithView:self.view];

// Add HUD to screen
[self.view addSubview:HUD];

// Regisete for HUD callbacks so we can remove it from the window at the right time
HUD.delegate = self;

HUD.labelText = @"Loading Events, Please Wait..";

int i = indexPath.row;

//Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:@selector(loadData:) onTarget:self withObject:i animated:YES];
}

我得到这个警告:

警告:传递'showWhileExecuting:onTarget:withObject:animated:'的参数3会使指针从整数开始而无需强制转换

有人可以解释一下我在做什么错吗?有人可以用Objective-C中的int来简要地解释这种情况吗?来自Java,我发现它们是如此混乱以致于感到奇怪。

最佳答案

问题在于showWhileExecuting:onTarget:withObject:animated:将对象作为其第三个参数。为了解决这个问题,您可以使用NSNumber类将整数包装为对象

[NSNumber numberWithInt:i]

然后,您必须通过调用来解开 loadData:方法中的参数
[argument intValue]

关于objective-c - 关于从整数转换指针而不进行强制转换的警告-需要说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6244115/

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