用于将值添加到数组,然后将结果与 iPhone 上的另一个数组进行比较的按钮

发布于 2024-08-24 23:03:14 字数 198 浏览 5 评论 0原文

我有十个按钮,每个按钮对应不同的数字。我希望记录按下这些按钮的顺序并将它们输入到一个数组中,然后将其与应用程序中的另一个静态数组进行比较。检查应在第 N 次按下按钮时完成,其中 N 等于另一个静态数组中的项目数。

如何 IA) 让按下按钮向数组添加一个值 B) 在按下第 N 个按钮后停止,该按钮等于我正在检查的数组中的数字数量 C) 将此数组与另一个数组进行比较?

I have ten buttons that each correspond to a different number. I'm looking to record the order that these buttons are pressed and enter them into an array and then compare it to another array that is static in the app. The check should be done on the Nth button press, where N equals the number of items in the other, static array.

How do I A) have a button press add a value to an array B) stop after Nth button press equal to amount of numbers in the array I'm checking against and C) compare this array to the other array?

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

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

发布评论

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

评论(1

ぃ双果 2024-08-31 23:03:14

您可以:

  1. 决定 N 并创建一个数组,其中 N 个数字作为 NSNumber 对象(NSArray 和 NSMutableArray 需要对象)。

  2. 将按钮链接到操作。

  3. 在操作方法中,检查每个按钮的第一个参数以确定按下了哪个数字。

  4. 将该数字添加到可变数组。

  5. 当数组的大小等于 N 时,进行检查:使用从 0 到 N-1 的 for 循环,并从每个数组中获取该索引处的对象。使用 isEqual: 来比较它们。如果任何比较失败,那么您就知道数组不匹配。否则,你就成功了。

You could:

  1. Decide on N and create an array with your N numbers as NSNumber objects (NSArray and NSMutableArray require objects).

  2. Link the buttons to an action.

  3. In the action method, check the first parameter against each button to determine which number was pressed.

  4. Add that number to a mutable array.

  5. When the array's size is equal to N, do your check: use a for loop from 0 to N-1 and get the objects at that index from each array. Compare them using isEqual:. If any comparison fails, then you know that the arrays don't match. Otherwise, you have success.

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