Iphone 如何推送视图、返回并返回视图?

Iphone 如何推送视图、返回并返回视图?,iphone,xcode,uitableview,uinavigationcontroller,pushviewcontroller,Iphone,Xcode,Uitableview,Uinavigationcontroller,Pushviewcontroller,我想建立一个应用程序,在iPhone上播放本地音频文件,但我的一些代码被卡住了。 我想知道如何在不向视图中插入任何新字符串的情况下,按下视图,返回uitableviewcontroller并使用按钮(如媒体播放器中的“正在播放”按钮)返回视图 多谢各位 我应该从代码中更改什么 在uitableviewcontroller中 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath

我想建立一个应用程序,在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];
}

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

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

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

补充马克所说的

一旦您激活了PopViewControllerAnimable,并且用户想要再次推送同一个控制器,您只需要保留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中的a行(歌曲)时创建新的mPlayerViewController<代码>(无效)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath{myDetViewCont=[[mPlayerViewController alloc]initWithNibName:@“mPlayerViewController”捆绑包:nil];