【问题标题】:How to push a view, go back and come back to the view?如何推视图,返回并返回视图?
【发布时间】:2011-07-16 23:23:43
【问题描述】:

我想构建一个在 iPhone 上播放本地音频文件的应用程序,但我的一些代码卡住了。 我想知道如何推送视图,返回 uitableviewcontroller 并使用按钮(如媒体播放器中的“现在播放”按钮)返回视图而不将任何新字符串推入其中..

谢谢你

我应该对我的代码进行哪些更改?

在 uitableviewcontroller..

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
    *)indexPath  {  
selectedSong = [directoryContent objectAtIndex:indexPath.row];  
NSString *storyLin = [[directoryContent objectAtIndex:[indexPath row]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  
patch = [NSString stringWithFormat:@"/%@", storyLin];


        myDetViewCont = [[mPlayerViewController alloc] initWithNibName:@"mPlayerViewController" bundle:nil];    
myDetViewCont.myProgLang = selectedSong; // assigning the correct value to the variable inside DetailViewController
        [self.navigationController pushViewController:myDetViewCont animated:YES];
        [myDetViewCont release]; // releasing controller from the memory

    }

在 mPlayerViewController.m 中

-(IBAction) backtoplayer{
    myDetViewCont = [[mPlayerViewController alloc] initWithNibName:@"mPlayerViewController" bundle:nil];
}

【问题讨论】:

    标签: iphone xcode uitableview uinavigationcontroller pushviewcontroller


    【解决方案1】:

    如果您已将视图推送到导航控制器上,只需将其弹出以查看下方的视图。

    也就是说,您推送myDetViewCont 的视图应该只是在backtoplayer 调用中弹出。

    - (IBAction)backToPlayer:(id)sender {
        [self.navigationController popViewControllerAnimated:YES];
    }
    

    【讨论】:

      【解决方案2】:

      补充马克所说的内容。

      一旦你 popViewControllerAnimated 并且用户想要再次推送同一个控制器,你只需要保留 mPlayerViewController 而不是释放它。

      如:

          if (!myDetViewCont)
          { // We only need to create it once.
                 myDetViewCont = [[mPlayerViewController alloc] initWithNibName:@"mPlayerViewController" bundle:nil];    
          }
          myDetViewCont.myProgLang = selectedSong;
          [self.navigationController pushViewController:myDetViewCont animated:YES];
          // no longer release here, move the release call to the dealloc
      

      【讨论】:

      • 太棒了!!!!谢谢你们两个!但是如何防止每次有人单击 uitableviewController 中的一行(歌曲)时创建一个新的 mPlayerViewController ? (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { myDetViewCont = [[mPlayerViewController alloc] initWithNibName:@"mPlayerViewController" bundle:nil];
      猜你喜欢
      • 2012-06-22
      • 1970-01-01
      • 2020-10-11
      • 1970-01-01
      • 2016-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多