0
我有2個按鈕:button1和button2。我想爲每個觸摸的對應按鈕創建一個NSSet,並且當按下按鈕2時要顯示set1值,反之亦然。按下按鈕1時僅設置1打印,按下按鈕2時僅設置2。我如何保留在button1動作中創建的設置,以便在按下按鈕2時可以顯示/使用它。看看我的簡單的代碼保留我新創建的NSSet
在實現我有:
- (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);
}
更簡單:'self.set1 = [NSMutableSet setWithArray:@ [@ 0,@ 1,@ 1,@ 4,@ 6,@ 11]];' – zaph 2014-09-13 04:30:17
同意。我試圖儘可能保持OP的代碼完整無缺,但這是一種更乾淨的方式。 – 2014-09-13 04:33:48
是的,我辯論過將這個評論添加到你的問題答案中。 – zaph 2014-09-13 04:35:16