Iphone 我对5个按钮使用相同的操作,想知道调用哪个按钮?
我对5个按钮使用了相同的操作,我想知道哪个按钮被称为在nib中为按钮赋予标记值,然后将其添加到按钮操作中:Iphone 我对5个按钮使用相同的操作,想知道调用哪个按钮?,iphone,ios5,ibaction,Iphone,Ios5,Ibaction,我对5个按钮使用了相同的操作,我想知道哪个按钮被称为在nib中为按钮赋予标记值,然后将其添加到按钮操作中: allbtn = sender; btntag = allbtn.tag; NSLog(@"btntag:%d",btntag); if(btntag==1) { } 现在您可以轻松找到您点击的按钮。在nib中为您的按钮赋予标记值,然后将其添加到按钮操作中: allbtn = sender; btntag = allbtn.tag;
allbtn = sender;
btntag = allbtn.tag;
NSLog(@"btntag:%d",btntag);
if(btntag==1)
{
}
现在您可以轻松找到您点击的按钮。在nib中为您的按钮赋予标记值,然后将其添加到按钮操作中:
allbtn = sender;
btntag = allbtn.tag;
NSLog(@"btntag:%d",btntag);
if(btntag==1)
{
}
现在您可以轻松找到您点击的按钮。在这种情况下,请尝试为按钮指定唯一的标记 在目标方法中,按如下所示重新获得按钮标记 乙二醇
在这种情况下,请尝试为按钮指定唯一的标记 在目标方法中,按如下所示重新获得按钮标记 乙二醇 使用: 然后使用:
-(void)aMethod:(id)sender{
UIButton *button = (UIButton *)sender;
int clickedBtnTag = button.tag ;
Nslog("clicked button tag is %d",clickedBtnTag);
}
尝试此操作,然后请还原我。使用:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
button.tag=1;
[view addSubview:button];
-(void)aMethod:(id)sender{
UIButton *button = (UIButton *)sender;
int clickedBtnTag = button.tag ;
Nslog("clicked button tag is %d",clickedBtnTag);
}
然后使用:
-(void)aMethod:(id)sender{
UIButton *button = (UIButton *)sender;
int clickedBtnTag = button.tag ;
Nslog("clicked button tag is %d",clickedBtnTag);
}
试试这个,然后请回复我
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
button.tag=1;
[view addSubview:button];
-(void)aMethod:(id)sender{
UIButton *button = (UIButton *)sender;
int clickedBtnTag = button.tag ;
Nslog("clicked button tag is %d",clickedBtnTag);
}
试试这个,然后请回复我
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
button.tag=1;
[view addSubview:button];
-(void)aMethod:(id)sender{
UIButton *button = (UIButton *)sender;
int clickedBtnTag = button.tag ;
Nslog("clicked button tag is %d",clickedBtnTag);
}
试试这个,然后请回复我。allbtn是UIButton*allbtn;allbtn为UIButton*allbtn;
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
button.tag=1;
[view addSubview:button];
-(void)aMethod:(id)sender{
UIButton *button = (UIButton *)sender;
int clickedBtnTag = button.tag ;
Nslog("clicked button tag is %d",clickedBtnTag);
}