从另一个视图类中隐藏带有标签的按钮不起作用。
Posted
技术标签:
【中文标题】从另一个视图类中隐藏带有标签的按钮不起作用。【英文标题】:Hide button with tag from another view class not working. 【发布时间】:2015-03-04 11:07:15 【问题描述】:我是 ios 新手。我制作了一个包含 Scrollview 的应用程序,在 Scrollview 中我添加了 10 页,每页包含 12 个按钮,并在我的 Scrollview 之外设置一个停止按钮,我想在按下停止按钮时设置,然后我想隐藏我选择的按钮,但它不起作用但是当我点击视图中的同一个按钮时,它是隐藏的,但是在这里我想在点击停止按钮时隐藏选定的按钮,我写代码就像
-(void)clikedOnButton:(UIButton*)whichButtonClicked
SaveSoundIntoArray *saveInfointoArray=[SaveSoundIntoArray sharedInstance];
if(whichButtonClicked.selected)
NSLog(@"button selected is:%@",whichButtonClicked);
NSUInteger butTag=(long)whichButtonClicked.tag;
NSLog(@"button clicked is:%ld",butTag);
switch (butTag)
case 1:
[[self.view viewWithTag:2] setHidden:YES];
[[self.view viewWithTag:121] setHidden:YES];
[saveInfointoArray.stopAllPlayer removeObject:saveInfointoArray.player1]; //when unselect the button ,remove object from array
[saveInfointoArray.saveButtonName removeObject:whichButtonClicked]; //when unselect object button remove object from array
[saveInfointoArray.selectedButtonButNotMoreThanTen removeObject:whichButtonClicked];
[saveInfointoArray.VolumeSaveForPlayer removeObjectForKey:@"1"];
totalSelectedButtonButNotMoreThanTen=[SaveSoundIntoArray countTotalSelectedButton:-1 and:1 and:0];
whichButtonClicked.selected =NO;
[saveInfointoArray.player1 stop]; //tap=2 , player1 stop
break;
这个方法在我的 view1 中现在我在按下停止按钮时调用这个方法
- (IBAction)stopAllPlayers:(id)sender
view1=[[View1 alloc]init];
SaveSoundIntoArray *saveInfointoArray=[SaveSoundIntoArray sharedInstance];
if(saveInfointoArray.stopAllPlayer.count == 0)
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Selection Empty" message:@"Your Selection is Empty" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
else
for(int i=0;i<saveInfointoArray.stopAllPlayer.count;i++)
copyOfSaveButtonName[i]=saveInfointoArray.saveButtonName[i]; //copy bcz loop mathi method call kriye tyare remove object thay 6
copyOfStopAllPlayer[i]=saveInfointoArray.stopAllPlayer[i]; //copy bcz stopallplayer removeObject
copyOfSaveButtonTag[i]=saveInfointoArray.saveButtonTag[i]; //copy bcz savebuttonTag removeObject
for(int i=0;i<copyOfStopAllPlayer.count;i++) //error here
NSLog(@"button:%@ and Player:%@ is STOP",copyOfSaveButtonName[i],copyOfStopAllPlayer[i]);
NSLog(@"button Tag is:%@",copyOfSaveButtonName[i]);
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button=copyOfSaveButtonName[i];
button.selected=YES;
NSLog(@"tag is :%@",copyOfSaveButtonTag[i]);
int currentTag=[copyOfSaveButtonTag[i] intValue]; //use buttonTag for comparison of buttontags
NSLog(@"currentTag: %d",currentTag);
if(currentTag>=1 && currentTag<=12)
[view1 clikedOnButton:button];
这里我没有从停止按钮获得按钮标签,我不知道,因为我对此感到困惑,请帮助我
谢谢。
【问题讨论】:
【参考方案1】:你可以使用:
UIButton *clickedButton = (UIButton*)sender;
NSLog(@"tag is : %i", clickedButton.tag)
【讨论】:
我在哪里使用它你能帮我吗? 我假设您的“copyOfStopAllPlayer” - 数组包含正确的对象,因为我不知道您的“SaveSoundIntoArray”类中发生的事情(如果不是,您应该在使用之前初始化“copyOfStopAllPlayer”数组) - 你可以使用“UIButton clickedButton = (UIButton)sender;”在迭代“copyOfStopAllPlayer”数组时,int currentTag = clickedButton.tag ...以上是关于从另一个视图类中隐藏带有标签的按钮不起作用。的主要内容,如果未能解决你的问题,请参考以下文章
从另一个视图重新绑定剑道网格到以前的搜索条件的正确方法是啥(后退按钮不起作用)
如果同时使用自动键盘隐藏,则文本字段的清除按钮 (x) 不起作用
如何从模型类中隐藏 MVC 4 上的标签,[HiddenInput(DisplayValue =false)] 不起作用
Javascript函数显示带有setTimeout的隐藏按钮在PDF中不起作用