我有 2 个按钮:button1 和 button2。我想为每个触摸的相应按钮创建一个 NSSet,并希望在触摸按钮 2 时显示 set1 值,反之亦然。按下按钮 1 时仅打印设置 1,按下按钮 2 时仅打印设置 2。如何保留在 button1 操作中创建的集合,以便在按下按钮 2 时显示/使用它。看看我的简单代码
在实施中,我有:
- (IBAction)button1:(UIButton *)sender {
//somecode
selectionButton1 = [[NSMutableArray alloc ] initWithObjects:@0,@1,@1,@4,@6,@11, nil];
NSMutableSet *set1 = [NSMutableSet setWithArray: selectionButton1];
NSLog(@"selectionButton1 = %@", set1);
NSLog(@"selectionButton2 = %@", set2);
}
- (IBAction)button2:(UIButton *) sender {
//somecode
selectionButton2 = [[NSMutableArray alloc ] initWithObjects:@0,@5,@6,@7,@8,@10, nil];
NSMutableSet *set2 = [NSMutableSet setWithArray: selectionButton2];
NSLog(@"selectionButton1 = %@", set1);
NSLog(@"selectionButton2 = %@", set2);
}