2013-01-03 38 views
-3

是否可以获取数组中的随机按钮的标签?访问数据的NSMutableArray

- (IBAction)actionButtonPressed:(id)sender 
{ 
    NSUInteger randomIndex = arc4random()% [_allButtons count]; 
    NSLog(@"%d", randomIndex); 
    NSLog(@"tag: %@",[_allButtons objectAtIndex:randomIndex]); 
} 

从日志中我得到这个:

UIRoundedRectButton:.... frame = (110 98; 50 44); opaque = NO; **tag = 5**; layer = CALayer..... 

是否有可能只是得到随机按钮的标签?

编辑:对不起_allButtons是一个NSMutableArray

回答

2

-

(IBAction) actionButtonPressed:(id)sender { 

    NSUInteger randomIndex = arc4random()% [_allButtons count]; 

    NSLog(@"%d", randomIndex); 

    NSLog(@"tag: %d", [[_allButtons objectAtIndex:randomIndex] tag]); 

} 
+0

感谢它的工作! –

+0

最后。现在很好。 – 2013-01-03 20:38:27

+0

那里,固定。编辑 –