隐藏其他视图类标记不起作用的按钮。

时间:2015-03-04 11:07:16

标签: ios objective-c uiview uibutton

我是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 个答案:

答案 0 :(得分:0)

你可以使用:

UIButton *clickedButton = (UIButton*)sender;
NSLog(@"tag is : %i", clickedButton.tag)