Cargue diferentes controladores de vista del objeto seleccionado de TableView

I need some assistance to approach this. I have created a UITabBarController where I have two tabs. And in one of them I made it to pop with UIPopoverController where I use a UITableView dentro de UIPopoverController. I load the tableView with two objects using table view datasource and I can see them when the UIPopoverController aparece.

You can check the screen shot here:

Captura de pantalla

Now what I want to achieve is that, when I click on feedback then I need to be directed/taken to feedbackViewController and the same with the other object Download, it should take me to the downloadViewController.

I know that I need to use table view method:

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

But I am not having an idea of how I can do this. So any general information of how I can approach this problem would be appreciated.

preguntado el 02 de febrero de 12 a las 11:02

1 Respuestas

It sounds quite simple. All you need to do is identify which button was pressed, in this case 0 for Feedback and 1 for Download. Then depending on that present the appropriate view controller. You will probably need to have a link to a parent, which will ultimately present the new view. Otherwise you will be presenting the view inside the popover controller.

Somewhere when creating/displaying your UIPopoverController create a reference to the parent

UIViewController *mainparent = _mainparent; //where _mainparent is the reference passed through.

Entonces en tu -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; Incluya lo siguiente.

if (indexPath.row == 0)
    [mainparent presentModalViewController:feedbackViewController animated:YES];
    [mainparent presentModalViewController:downloadViewController animated:YES];

That will modally present the required view controllers.

Respondido 02 Feb 12, 15:02

Hi Amit, thanks for your reply. I have few questions regarding this. What do you mean by reference to the parent. In my design I am creating the UIViewControllers and handling them using AppDelegate.m using - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions. I created FirstViewController (webview), SecondViewController (where I pop up the popovercontroller with tableview) and a popovercontroller. Now which would be the parent controller in my case. Bear me for my naive, Im getting into IOS. Thanks - 125369

One more info, I created a Empty Application using xcode 4.2.1 and from there I added all the required view controllers - 125369

The parent would be which ever viewcontroller you want to replace. So I think it might be your firstViewControler, but depending on your application, you might want to be replacing you secondviewcontroller. - Amit Shah

Hi Amit, thanks once again for your answer that worked. I have got another strange problem. In my feedbackViewController I cannot find the tabBarController with tabs any more. Even if I switch back to FirstViewController using a backButton, even in the FVC the tabBar items are vanishing. Could you let me know how to fix this. Thanks for your replies dude. - 125369

No problem. Would you mind accepting if this works?. It depends on how you've organised the tab bar, what you should be doing is having the tab bar as the main view, then the viewcontroller it is displaying should be changed, maybe using the UINavigationController. ¿Tiene sentido? - Amit Shah

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.