9

我想建立一個應用程序來播放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]; 
} 

回答

11

如果您有推一個視圖到導航控制器,只是彈出它的下方查看視圖。

也就是說,您推動myDetViewCont的視圖應該彈出在backtoplayer調用中。

- (IBAction)backToPlayer:(id)sender { 
    [self.navigationController popViewControllerAnimated:YES]; 
} 
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 
+0

AMAZING !!!!謝謝你們兩位!但是,我怎樣才能防止每次有人點擊uitableviewController中的一行(歌曲)時創建一個新的mPlayerViewController? (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath :(NSIndexPath *)indexPath {myDetViewCont = [[mPlayerViewController alloc] initWithNibName:@「mPlayerViewController」bundle:nil]; ' – Alby 2011-03-18 05:18:37