gpt4 book ai didi

ios - Xcode - 保存按钮点击顺序并按保存顺序重播操作?

转载 作者:行者123 更新时间:2023-11-29 02:55:10 24 4
gpt4 key购买 nike

我正在尝试保存按下按钮的顺序,然后重播该顺序并按照最初按下按钮的顺序运行分配给按钮的操作?谁能帮我解决这个问题?

最佳答案

每个 UIControl 元素都有一个标签,您可以使用它来识别将要点击的各种按钮。当点击每个按钮时,将调用与该按钮关联的方法(选择器)(您甚至可以为所有按钮调用一个选择器并通过它们的标签区分它们)。

当每个按钮被点击时,通过将每个按钮的标签添加到队列(或在 Objective-C 中:NSMutableArray)来跟踪哪个按钮被点击。然后要重放操作,您只需从队列中读取标签值并调用相应的选择器即可。

举例说明:

@property (nonatomic, strong) NSMutableArray *taskArray;

// in your init or viewDidLoad:
_taskArray = [NSMutableArray new];

// in the selector that is called by *all* buttons
-(IBAction) buttonTapped:(id)sender {
[_taskArray addObject:[NSNumber numberWithInteger:sender.tag]];
[self executeActionWithTag:sender.tag];
}

-(void) executeActionWithTag:(NSUInteger)tag {
if(tag == 1) {
// perform specific action 1 ...
} else if (tag == 2) {
// perform specific action 2 ...
}
// ...
}

-(void) replayButtonActions {
for (NSNumber *tag in _taskArray) {
[self executeActionWithTag:[tag integerValue]];
}
}

关于ios - Xcode - 保存按钮点击顺序并按保存顺序重播操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23992109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com