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

标签 ios xcode ios5 uibutton selector

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

最佳答案

每个 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/

相关文章:

ios - 使用无线连接 Iphone 不工作

ios - 如何使用 Storyboards 和 Tab Bar Controller 作为初始 Controller 共享 UIManagedDocument?

ios - Phonegap验证错误: Unable to validate your application, 包中不包含info.plist

iphone - 动画调整 UITableView 的 UIView 标题

IOS Swift TI SensorTag2数据转换

iphone - UITableViewController 不加载数据

iphone - 如何在 mysql 中插入 utf-8 mb4 字符(ios5 中的表情符号)?

ios - 设置 psmultivaluespecifier 中的键/值的分隔符或分组是否可能?

ios - 如何添加新 StoryBoard,并将其设置为 Main StoryBoard xCode 而不会出错

ios - 如何从字符串列表中找到特定的字符串?