如何推送一个视图,返回并返回视图?

发布于 2024-10-22 20:32:47 字数 1194 浏览 1 评论 0原文

我想构建一个在 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];
}

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..

THANK YOU

What should I change from my codes ?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝梦月影 2024-10-29 20:32:47

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

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

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

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

That is, the view you push myDetViewCont should just be popped in the backtoplayer call.

- (IBAction)backToPlayer:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
帅冕 2024-10-29 20:32:47

添加到马克所说的内容中。

一旦你 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

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.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文