xcode 如何推送视图,返回并返回视图?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5332199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:32:24  来源:igfitidea点击:

How to push a view, go back and come back to the view?

iphonexcodeuitableviewuinavigationcontrollerpushviewcontroller

提问by Alby

I want to build an app for playing local audio files on the iPhone but I'm stuck with some of my codes. I'm wondering how you can push a view, come back to the uitableviewcontroller and use a button ( like the "NOW PLAYING" button in the media player) to come back to the view without pushing any new string into it..

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

THANK YOU

谢谢你

What should I change from my codes ?

我应该从我的代码中更改什么?

in the 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

    }

in mPlayerViewController.m

在 mPlayerViewController.m

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

回答by MarkPowell

If you have pushed a view onto the navigation controller, just pop it to review the view underneath.

如果您已将视图推送到导航控制器上,只需弹出它即可查看下面的视图。

That is, the view you push myDetViewContshould just be popped in the backtoplayercall.

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

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

回答by NWCoder

To Add to what Mark said.

添加到马克所说的内容。

Once you've popViewControllerAnimated and the user want to push the same controller again, you just need to keep the mPlayerViewController rather than release it.

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

Such as:

如:

    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