-3

是否可以在数组中获取随机按钮的标签?

- (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

4

1 回答 1

2

-

(IBAction) actionButtonPressed:(id)sender {

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

    NSLog(@"%d", randomIndex);

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

}
于 2013-01-03T20:35:34.940 回答