Question

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];
}
Was it helpful?

Solution

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

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top