[菜鸟手记]根据点击的button执行不同操作

5 views
Skip to first unread message

Jehovah-鱼

unread,
Dec 15, 2011, 11:57:06 PM12/15/11
to iOS development
//通过button的title判断
-(IBAction)buttonAction:(id)sender
{
NSString *command = [sender titleForState:UIControlStateNormal];
NSLog(@"%@", command);
if([command isEqualToString:@"button_title_one"]) {
//code here
} else if([command isEqualToString:@"button_title_two"]) {
//code here
}
}
//通过设置的button的tag判断
-(IBAction)clickRegionButton:(id)sender
{
UIButton *button = (UIButton*)sender;
int btnTag = [button tag];

switch (btnTag) {
case 1: { //code here}
case 2: { //code here}
}
}

Reply all
Reply to author
Forward
0 new messages