Add a multiple buttons to a view programatically, call the same method, determine which button it was
for( int i = 0; i < 5; i++ ) { UIButton* aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [aButton setTag:i]; [aButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [aView addSubview:aButton]; } // then ... - (void)buttonClicked:(UIButton*)button { NSLog(@"Button %ld clicked.", (long int)[button tag]); }
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。