我在下面的代碼上創建了for循環的一些按鈕。帶IBAction的IOS UIButton
UIView *buttonsView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _viewEmoji.frame.size.width, 35)];
[buttonsView setBackgroundColor:[UIColor greenColor]];
for (int i = 0; i < myObject.count; i ++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(35*i + 5, 0, 35, 35)];
[button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@", [myObject objectAtIndex:i]]] forState:UIControlStateNormal];
[button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
[buttonsView addSubview:button];
}
現在,我如何點擊按鈕來處理事件。
每個按鈕被點擊,它將處理1個事件。例如:如果我有2個按鈕是由for循環創建的。當我點擊按鈕1,它會記錄1,當我點擊按鈕2,它會記錄2.
每個按鈕提供一個獨特的'tag'值。 – rmaddy