从 NSMutable 数组中检索整数数据

发布于 2024-12-24 15:57:10 字数 697 浏览 2 评论 0原文

我在从 NSMutable 数组获取整数值时遇到问题。我在屏幕上有几个具有匹配标签属性值的按钮(button1 的标签值为 1 等)。当按下按钮时,我将数字标签值添加到 NSMutable 数组中。稍后,我想循环访问对象以查看按下哪些值来构建查询。但是,我在循环中收到 SIGABRT 错误。

//pairNumber is the 'tag' value from a button
-(void) numberSearchArray:(NSInteger)pairNumber;
{
    [self.queryPairs addObject:[NSNumber numberWithInt: pairNumber]];
}

//***************************

-(void)buildQuery:(BOOL *)function numberToUse:(NSInteger)number
{
   //other code not shown

   int pair_values [6];
   int compare_total = [queryPairs count];

   for (int x = 0; x<=compare_total-1; x++){
     pair_values[x] = (NSUInteger)[queryPairs objectAtIndex:x];  //SIGABRT error

   //code continued...
}

I am having an issue getting integer values form an NSMutable array. I have several buttons on the screen with a matching tag property value (button1 has a tag value of 1, etc.). When a button is pressed, I add the numeric tag value to the NSMutable array. Later, I want to loop through the objects to see what values are pressed to build a query. However, Iget a SIGABRT error in the loop.

//pairNumber is the 'tag' value from a button
-(void) numberSearchArray:(NSInteger)pairNumber;
{
    [self.queryPairs addObject:[NSNumber numberWithInt: pairNumber]];
}

//***************************

-(void)buildQuery:(BOOL *)function numberToUse:(NSInteger)number
{
   //other code not shown

   int pair_values [6];
   int compare_total = [queryPairs count];

   for (int x = 0; x<=compare_total-1; x++){
     pair_values[x] = (NSUInteger)[queryPairs objectAtIndex:x];  //SIGABRT error

   //code continued...
}

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

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

发布评论

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

评论(2

╭⌒浅淡时光〆 2024-12-31 15:57:10

你需要做:

[[queryPairs objectAtIndex:x] intValue];

you need to do:

[[queryPairs objectAtIndex:x] intValue];
帅冕 2024-12-31 15:57:10

您没有对pair_values进行边界检查,您的queryPairs数组中是否有超过6个项目?

You're not bounds checking pair_values, do you have more than 6 items in your queryPairs array?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文