UIButton做不同的动作ios
我有两个导航按钮(左和右)和两个类别按钮(例如loveCategory和otherCategory)。当我选择loveCategory时,我希望我的导航按钮仅在loveCategory中显示(在我的情况下为Images),当我按otherCategory时,导航按钮应该只能从otherCategory显示(图像)(即当我按左右按钮)。UIButton做不同的动作ios
让我知道如果这不明确。
这里是我的代码:
-(IBAction)NavigationBtnTapped:(UIButton*)sender {
UIButton *button=sender;
switch (button.tag) {
case 1:
//statements
break;
case 2:
//statements
break;
default:
break;
}
}
-(IBAction)loveCategory {
}
-(IBAction)otherCategory {
}
我如何调用一个动作与另一动作中
-(IBAction)loveCategory
{
-(IBAction)NavigationBtnTapped:(id)sender
{
// Is it possible to call an action within another action?
}
}
给标签1和2的按钮,并尝试这个办法:
-(IBAction)NavigationBtnTapped:(id)sender {
switch ([sender tag]) {
case 1:
//statements
break;
case 2:
//statements
break;
default:
break;
}
}
我已经这样做了..我的问题是我如何使用NavigationBtnTapped行动来执行其他操作?我真的想在另一个方法中调用这个NavigationBtnTapped方法 - (IBAction)loveCategory – Vikr 2013-03-21 12:49:46
根据点击哪个按钮调用相关的方法。有什么问题 ? – Petar 2013-03-21 12:53:35
我该如何调用 - (IBAction)loveCategory { - (IBAction)NavigationBtnTapped:(id)sender //是否可以在另一个操作中调用一个动作? } – Vikr 2013-03-21 13:00:02
AnOther Way is ....
给予标签均为UIButton
。
诸如此类
button1.tag = 101;
button2.tag = 102;
两个UIButton
具有相同的方法调用。
诸如此类,
-(void)buttonTapped:(UIButton *)sender
{
if(sender.tag == 101)
{
// code for loveCategory
}
if(sender.tag == 102)
{
// code for otherCategory
}
}
您可以通过设置在最后做这个
int selectedCategory = 0;
-(IBAction)NavigationBtnTapped:(UIButton*)sender {
UIButton *button=sender;
switch (button.tag) {
case 1:
//statements
if(selectedCategory == 0){
// go left for lovecategory
}else{
// go left for OtherCategory
}
break;
case 2:
//statements
if(selectedCategory == 0){
// go right for lovecategory
}else{
// go right for OtherCategory
}
break;
default:
break;
}
}
-(IBAction)loveCategory {
selectedCategory = 0;
}
-(IBAction)otherCategory {
selectedCategory=1;
}
选择哪一类标志做,这是你想要的吗?
对于另一个动作中调用动作
-(IBAction)loveCategory
{
[self NavigationBtnTapped:null];
}
-(IBAction)NavigationBtnTapped:(id)sender
{
// Is it possible to call an action within another action?
}
我想爱情类中调用NavigationBtnTapped像下面 - (IBAction为)loveCategory { - (IBAction为)NavigationBtnTapped:(ID)发送 {// 是否可以调用另一个行动中的作用? (IBAction)loveNavigationBtnTapped:(UIButton *)发件人,并试图在(-IBAction)内调用它(loveCategory {[code] } – Vikr 2013-03-21 13:06:04
@Vikr我编辑了我的答案 – 2013-03-21 14:56:38
它似乎没有工作。 self loveNavigationBtnTapped:null]; }和它的不工作.. – Vikr 2013-03-22 05:10:18
另一种方式是有2个UIButtons和两个UIImages但它不是这样做的好方法:d
一开始loveCategory的按钮隐藏= NO,它的图像隐藏= YES,otherCategory的按钮= YES,其图像隐藏= NO。
当你点击loveCategory的按钮,loveCategory的按钮隐藏= YES和图像隐藏= NO,也为otherCategory的按钮隐藏= NO和图像隐藏= YES
发现了答案!
在头文件
BOOL isLove,isOther;
在FPGA实现文件
- (void)viewDidLoad
{
isOther=TRUE;
isLove=FALSE;
}
-(IBAction)NavigationBtnTapped:(UIButton*)sender {
if (isLove) {
// Statement
}
else
{
//statement
}
如果需要使用 “否则,如果” 检查多个按钮。
@chirag - 拼写错误?大声笑 – Vikr 2013-03-21 12:47:25
我没有得到你完全请解释更多。你是什么意思'只从loveCategory'和'只从otherCategory'。你想为不同类别的不同导航按钮吗? – 2013-03-21 12:47:33
仍然接受:) – 2013-03-21 12:48:16