-3

我有一个字符串数组,我想在每次按下应用程序中的按钮时访问该数组中的下一个元素,我不想弹出重复的字符串,所以我想遍历整个数组,然后在我到达数组末尾后重新开始......所以每次按下按钮都会显示数组中的下一个元素......我的 buttonPressed 方法在 viewDidLoad 方法中。泰

4

2 回答 2

0
set index = 0

on button press:
show(strings[index])
increment index
if index is equal to strings.length then set index = 0
于 2013-08-15T20:10:38.893 回答
0

你可能会这样做:

@interface ViewController() {
    int index;
}
// ...
end

@implementation ViewController

- (void)viewDidLoad {
    index = 0;
}

- (IBAction)buttonPressed:(id)sender {
    if (index == yourArray.count)
        index = 0;
    NSString *nextItem = [yourArray objectAtIndex:index];
    // Use the string you just got...
    index++;
}

end
于 2013-08-15T20:19:35.437 回答