views:

255

answers:

1

Hi all,

I'm building an iPhone application with a UITableView. On selecting a row a web page is loaded in a UIWebView in the next tab along. Currently this is all working, however, how can I set the application to automatically move into the tab where the webpage has been loaded into the UIWebView?

Is there some form of animation that slides into the next tab along, or just some simple function to change into another tab?

Code-wise, I'm controlling this within didSelectRowAtIndexPath and currently have:

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

NSDictionary * story = [stories objectAtIndex:[indexPath row]]; 
NSString * storyLink = [NSString stringWithFormat:[story objectForKey:@"link"]];

webview.scalesPageToFit = YES;
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:storyLink]]];


}

Again just to clarify, the webpage successfully loads into the UIWebView 'webview' in the next tab along, but I have to manually click the tab to see it. How can the application automatically move into the next tab once the webpage has loaded without having to manually click the next tab?

Thanks in advance,

Benji

+1  A: 

Assuming you have just one TabBarView for your application, and that its set up as an IBOutlet in your AppDelegate class, you can just use selectedIndex as follows:

myAppDelegate.tabBarController.selectedIndex = 1;

where tabBarController is the IBOutlet linked to your tab bar in the MainWindow.XIB file.

The above example would change to the second tab (tabs start from 0 of course).

I don't believe the change is animatable but I confess I haven't tried it!

Hope that helps!

h4xxr
Fantastic, fantastic, fantastic! Thanks a lot!
Benji Barash
You're welcome. Any chance of clicking on my up arrow?! ;)
h4xxr
I would, but apparently it requires a rep level of 15 :p Once I've got that high I'll come back and up it ;)
Benji Barash
lol i forgot that! Well, that can be easily fixed :D
h4xxr
Clicked the up arrow for you :)Thanks again.
Benji Barash