Objective c 从 NSDictionary 设置选择器值

发布于 2024-11-15 14:01:42 字数 523 浏览 3 评论 0原文

另一个可能很简单的问题,在尝试了好几个小时后,我现在很困惑。简单地说,我想从 NSDictionary 设置选择器的值,我不介意!我尝试过的每种方法几乎都会给我警告传递 selectRow inComponentAnimated 的参数 1 使指针中的整数不进行强制转换。这是有道理的,尽管我似乎无法修复它!任何帮助将不胜感激!下面的代码片段...

NSArray *myValue = [parsedJson objectForKey:@"Details"];
NSEnumerator *myEnumerator = [myValue objectEnumerator];
NSDictionary* myItem;

int i = 0;
while (myItem = (NSDictionary*)[myEnumerator nextObject])
{
    [myPickerView selectRow:[myItem objectForKey:@"Value"] inComponent:i animated:YES];
    i++;
}

Another, probably simple problem that, having tried for a good few hours now I'm pretty stumped on. Simply, I want to set the value of a picker from a NSDictionary, I don't mind! Every way I have tried pretty much gives me the warning Passing argument 1 of selectRow inComponent animated' makes integer from pointer witout a cast. Which makes sense, though I seem to be failing miserable at fixing it! Any help would be greatly appreciated! Snippet of code below...

NSArray *myValue = [parsedJson objectForKey:@"Details"];
NSEnumerator *myEnumerator = [myValue objectEnumerator];
NSDictionary* myItem;

int i = 0;
while (myItem = (NSDictionary*)[myEnumerator nextObject])
{
    [myPickerView selectRow:[myItem objectForKey:@"Value"] inComponent:i animated:YES];
    i++;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尽揽少女心 2024-11-22 14:01:42

假设您的值响应 intValue 消息(例如,数字存储在 NSNumber 或 NSString 中),那么以下操作应该有效:

[myPickerView selectRow:[[myItem objectForKey:@"Value"] intValue]
            inComponent:i animated:YES];

Assuming your value responds to intValue message (e.g. number is stored in NSNumber or NSString) then the following should work:

[myPickerView selectRow:[[myItem objectForKey:@"Value"] intValue]
            inComponent:i animated:YES];
他不在意 2024-11-22 14:01:42

selectRow 参数需要一个整数,请尝试以下操作:

[myPickerView selectRow:[[myItem objectForKey:@"Value"] integerValue] inComponent:i animated:YES];

The selectRow parameter is expecting an integer, try this:

[myPickerView selectRow:[[myItem objectForKey:@"Value"] integerValue] inComponent:i animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文