Benji Barash
Benji Barash

Reputation: 423

Automatic Tab Switch

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

Upvotes: 2

Views: 529

Answers (1)

h4xxr
h4xxr

Reputation: 11475

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!

Upvotes: 2

Related Questions