Question

Here's my problem. I have data being passed into the 'second view controller' by mySQL which currently works great. But when I select on any of the from (UITableView) cells, I am currently not able to open a new view to show the data.

I believe the code issue is with

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
detailedViewController *productinfo = [self.storyboard instantiateViewControllerWithIdentifier:@"productDetails"];

//Retrieve current user array
foodProducts *currentProduct = [bakeryProductArray objectAtIndex:indexPath.row];
productinfo.productName = currentProduct.productName;
productinfo.productImage = currentProduct.productImgUrl;
productinfo.productDescription = currentProduct.productDescription;

[self.navigationController pushViewController:productinfo animated:YES];

}

There have been others who have over came this using nibs but not storyboard.

Can someone point out where I have gone wrong or something I have fundamentally missed?

(I have another project which fully working with navigation controller only. Though this is the 1st project which I have tried to use with the tab bar navigation).

Was it helpful?

Solution

The best way to handle this with a storyboard is to create a segue to the detail view from your mainViewController. This can be from your actual cell or from the controller. In your prepare for segue method, pass the object to the detail view. This uses a fetchedResultsController but the idea is the same. Get the selected cell and pass the object to the detail view.

Here is a sample of how you could pass it while using a segue from the cell itself. Create a segue from the tableViewCell in IB for "selection". Drag that segue to your detailViewController and set the identifier to ShowDetailView then add the following prepareForSegue method.

Make sure to have a property (foodProduct) on your detailViewController that will hold the reference to your selected object. That's what you will pass from your mainViewController.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
    if ([[segue identifier] isEqualToString:@"ShowDetailView"]) 
    {
        DetailViewController *detailViewController = [segue destinationViewController];
        foodProducts *currentProduct = [bakeryProductArray objectAtIndex:[self.tableView indexPathForSelectedRow]];
        detailViewController.foodProduct = currentProduct;
    }
}

OTHER TIPS

try this .....

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Decriptionview *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Decription"];//@"Decription" is Storybord Id of UiViewController of Decriptionview
    detail.wndecDecription=[SortedDecription1 objectAtIndex:indexPath.row];
    detail.wndectitle=[SorttedTitle1 objectAtIndex:indexPath.row];
    detail.wndeclink=[SortedLink1 objectAtIndex:indexPath.row];
    detail.wndecdate=[SorttedDate1 objectAtIndex:indexPath.row];
    detail.imgeurl=[sorttedMainImage1 objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:detail animated:YES];

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top