0

I try to create my first iPhone application. I created two differents views in my Storyboard. A "master" and a "detail" view. I embedded the Master View into a Navigation Controller. The Master View is made of an UITableView, with custom cells.

I try to show the Detail View when I tap the cell. but I don't understand how to make that... I created a "view detail" segue between the cell and the Detail View, but when I tap the cell, nothing happens.

Thanks for the help.

ThibaultV
  • 529
  • 1
  • 5
  • 24
  • There is an XCode sample the does the exact same thing you are trying to do. Just give it a check. You can find it in **XCode > File > New > Project... > iOS > Application > Master Detail Application** – jMelnik Sep 19 '14 at 18:27
  • I used the Master Detail Application for my app. Everything worked until I create my custom UITableViewCell. – ThibaultV Sep 19 '14 at 19:34
  • Check this it similar with your problem: http://stackoverflow.com/a/28428558/4935811 – Sour LeangChhean Feb 23 '17 at 04:49

3 Answers3

0

Embed the UITableView into a navigation controller.

dmerlea
  • 894
  • 4
  • 12
0

Do you have a code in your method "didSelectRowAtIndexPath" in your table?

  • Yes, I wrote `[self performSegueWithIdentifier:@"showDetail" sender:self];` – ThibaultV Sep 19 '14 at 19:31
  • @ThibaultV, you shouldn't be calling performSegue if you made the segue from the cell to the next controller -- it should be called automatically when you select your cell. – rdelmar Sep 19 '14 at 19:51
  • try this code: `VIEWCONTROLLERTHATUNEEDTOPUSH* viewController = [[VIEWCONTROLLERTHATUNEEDTOPUSH alloc] init]; [self.navigationController pushViewController:viewController animated:YES];` don't forget to change the VIEWCONTROLLERTHATUNEEDTOPUSH for your main view controller! – Vinícius Eduardo Sep 19 '14 at 20:23
  • Nothing. But I think I found something interesting. I added a NSLog command into the didSelectRowAtIndexPath, and when I tap the cell, nothing appears in the console. – ThibaultV Sep 19 '14 at 20:54
  • @ThibaultV, did you set the table view's delegate? – rdelmar Sep 19 '14 at 23:35
  • No, I added the Table view's delegate and now it's working. When I tap the cell, I switch to the "View Detail". But I still have some problems. First : the "showDetail" segue is not automatically called when I tap the cell. And the transition animation is not smooth. – ThibaultV Sep 20 '14 at 01:34
  • When I create the segue, I click on the "Cell" of my TableView, I hold the ctrl key and I drag to the Details View. I choose "show details". But, when I do that, when I tap the cell, the Details View is shown, but the segue is not performed. I wrote `- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"showDetail"]) { NSLog(@"Segue done"); } }` to be sure, and nothing. I have to add `[self performSegueWithIdentifier:@"showDetail" sender:self];` and when I do that, a white page appears. – ThibaultV Sep 20 '14 at 12:24
0

You can try with this solution here:

The problem is that you're not handling your data correctly. If you look into your currentResponse Array, you'll see that it holds NSDictionaries but in your prepareForSegue you try to cast a NSDictionary to a NSArray, which will make the app crash.

Change the data variable in RestaurantViewController to a NSDictionary and change your prepareForSegue to pass a a NSDictionary

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if let cell = sender as? UITableViewCell {
    let i = redditListTableView.indexPathForCell(cell)!.row
    if segue.identifier == "toRestaurant" {
        let vc = segue.destinationViewController as RestaurantViewController
        vc.data = currentResponse[i] as NSDictionary
    }
}
}
Community
  • 1
  • 1
Sour LeangChhean
  • 7,089
  • 6
  • 37
  • 39