10

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

2 回答 2

12

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

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

- (IBAction)backToPlayer:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
于 2011-03-16T21:49:37.237 回答
4

补充马克所说的。

一旦你 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
于 2011-03-16T21:56:24.177 回答