如何推送视图,返回并返回视图?
问题描述:
我想建立一个应用程序来播放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];
}
答
如果您有推一个视图到导航控制器,只是弹出它的下方查看视图。
也就是说,您推动myDetViewCont
的视图应该弹出在backtoplayer
调用中。
- (IBAction)backToPlayer:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
答
增加到什么马克说。
一旦你已经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
AMAZING !!!!谢谢你们两位!但是,我怎样才能防止每次有人点击uitableviewController中的一行(歌曲)时创建一个新的mPlayerViewController? (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath :(NSIndexPath *)indexPath {myDetViewCont = [[mPlayerViewController alloc] initWithNibName:@“mPlayerViewController”bundle:nil]; ' – Alby 2011-03-18 05:18:37