开发者

Button to add value to array and then compare result with another array on IPhone

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开发者_JAVA百科 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜