我想构建一个用于在iPhone上播放本地音频文件的应用程序,但我遇到了一些代码。我想知道如何按下视图,返回uitaiteViewController并使用按钮(例如媒体播放器中的“现在播放”按钮)返回视图,而无需将任何新的字符串插入其中。

谢谢你

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

在uitaiteViewController中。

    - (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];
}

其他提示

增加马克所说的话。

popviewControllerralleranimated并需要再次推动同一控制器后,您只需要保留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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top