views:

329

answers:

2

Hello all

Is it possible to select a row in a previous UITableview. I provided image samples to get a more clear picture of what is happening exactly.

http://img186.imageshack.us/img186/933/picture8a.png

http://img405.imageshack.us/img405/9327/picture9d.png

http://img200.imageshack.us/img200/5386/picture10thm.png

At the morning workout screen , one can select a row and behind it so it will play a Movie. If the movie plays you can press the secondbutton and it will take you to the final table. If you press the backbutton you will simply return to the previous screen.

Now here is where my problem lies. If i'm in my final screen after pressing the secondbutton and I press on the backbutton it would be great if it could play the previous video( in other words the video connected to the previously selected cell)

So if it's possible for me to create a function or some sort of action that can actually select the previously selected row from the first field ( for instance Lunge Forward in this example ). perhaps with some like

previousRow = [ self.tableView indexPathForSelectedRow];
[self tableView:[self tableView] didSelectRowAtIndexPath:previousRow];

just doing something there

Even if it's not possible I would appreciate it if someone would let me know.

edit: Here is some code behind the cell when it's going to play a video

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

//Get the dictionary of the selected data source.
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];

//check to see if video must be played
NSString *playVids = [dictionary objectForKey:@"playVids"];

finalscreen = [dictionary objectForKey:@"finalScreen"];

if(playVids  == nil )
{
if(CurrentLevel != 0 )
{
if( finalscreen == nil )
{
NSString *movies = [dictionary objectForKey:@"movieID"];
NSURL *movie = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:movies ofType:@"m4v"]];
theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movie];
[theMovie setOrientation:UIDeviceOrientationPortrait animated:NO];
[theMovie setScalingMode:MPMovieScalingModeAspectFit];
theMovie.backgroundColor = [ UIColor whiteColor];
[[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(myMovieFinishedCallback:) 
name:MPMoviePlayerPlaybackDidFinishNotification 
  object:theMovie]; 

[theMovie play];
[self getToolBarStuff];

lblTitle.text = [dictionary objectForKey:@"Title"];
[[[UIApplication sharedApplication]keyWindow]addSubview:toolbar2];
[[[UIApplication sharedApplication]keyWindow]addSubview:imageView];
[[UIApplication sharedApplication]keyWindow]addSubview:lblTitle];
}
}

else 

{
WebViewController *web = [[WebViewController alloc] initWithNibName:@"WebView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:web animated:YES];
[web release];
}
}
else {
//Prepare to tableview.
rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];

//Increment the Current View
rvController.CurrentLevel += 1;

//Set the title;
rvController.CurrentTitle = [dictionary objectForKey:@"Title"];

//Push the new table view on the stack
[self.navigationController pushViewController:rvController animated:YES];
rvController.tableDataSource = Children;
[rvController release];

}
}

I get my info/feeds from a dictionaryfile and also different tags in my dictionary tell my tableview when to play the video and when not( playVids ).

so to be exact I have a start screen which brings you to a second screen and that one brings you to the morning workout screen and from there if you click a cell it will play a (different with every cell) video. I can't use the standard design from apple(with the backbutton above) since this assignment specifically asks to use their own design. That's the reason why i created my own tabbar and backbutton.

My backbutton looks like this

-(void)back_clicked:(id)sender 
{
[self.navigationController popViewControllerAnimated:YES];

CurrentLevel--;

switch( CurrentLevel ) {
case 0;
[toolbar removeFromSuperView];
default: 
break;
}
}

So if I'm in the last screen I just pop that screen to return to my previous one( the morning workout). And what actually has to be done is pop that screen and play the last video. I thought I could do that by popping the last screen and then selecting the previously clicked cell in morning workout.

Any thoughts on that.

+1  A: 

I am not sure I understand your problem exactly here. Can you show a bit more code? You have 3 view controllers, right? Are you using a standard navigation controller pattern with push/pop to get from one to the other? It looks like maybe you aren't since the buttons are in an odd layout.

If you are then pressing the back button can just pop view 3 and go back to view 2 naturally (it will still be there, so the video should still be playable) so I don't see why you need to mess with the table in view 1 in order to find that and make it show again. You should just be able to hook into viewWillAppear and do the same thing you did when coming from view 1.

And if you aren't using a standard navigation controller pattern then maybe this is the problem. From a UI perspective you probably should do that anyway - people will expect a standard back button in the title bar.

I am pretty sure your problem is soluble anyhow - you can always pass object references from one view to the other when creating them for example - but I don't think you need to resort to the method you have in mind.

edit: reading the additional detail I see you are indeed using push/pop. So you have a stack of views, and when one is popped it uncovers the one beneath it, right? It should therefore be possible to do what you want by implementing the viewWillAppear or viewDidAppear methods in your controller. When your final screen is popped, if I understand correctly it will uncover the view which is able to play the movie. Your viewcontroller will get the viewWillAppear / viewDidAppear messages in that case - by maintaining state and receiving those messages you can then implement logic to decide whether or not you need to play the movie. Rather than call the didSelectRow. method again you could perhaps put the movie play stuff in its own method so you can call from either viewDidAppear or didSelectRow...

frankodwyer
thank you very much for your reply. Indeed I do have more then one controller. However these do not really apply here. I'm using a drilldowntable sort of like this one. http://www.iphonesdkarticles.com/2009/03/drill-down-table-view-with-detail-view.html.So i'm using one controller to control the tableviews. And there is also a different controller for my overlayview with the video's( the title and bottombar). I'm going to edit my question and add some code to be more exact. Because in this commentbox it's a pain to read I assume;).
A: 

I also am not sure that I fully understand your question either but it sounds similar to a problem I was working on recently. Check out this post on using up down arrows to move through the parent table while in a detail view. My app was based on the same sample code so you should be able to get this to work without much trouble.

http://stackoverflow.com/questions/1180431/up-down-arrows-in-nav-bar-of-detail-view-to-page-through-objects-in-parent-table

Jonah
It's indeed simular with the difference that my button is in the next tableview pushed on top of the previous one;)