Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

johnmerlino

macrumors member
Original poster
Oct 22, 2011
81
0
Hey all,

I am using the new storyboard feature. Basically, I have a table, and when you click on a cell, depending on the value held in one of my methods, I want to display a specific view. There are 4 views associated with this table cell of the table. And each display condiitionally based on a value of one of my methods declared and initialized in the table view class. Problem is I am not sure how to set up the segue, since they can only point to one view.


For example, typically you would do some setup in the prepareForSegue method:

Code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Make sure we're referring to the correct segue
    if ([[segue identifier] isEqualToString:@"ShowSelectedMovie"]) {
        
        // Get reference to the destination view controller
        RemoteControlViewController *vc = [segue destinationViewController];
        
        // get the selected index
        NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row]; //this is where we set a value to selectedIndex method
        
        // Pass the name and index of our film
        [vc setSelectedItem:[NSString stringWithFormat:@"%@", [units objectAtIndex:selectedIndex]]];
        [vc setSelectedIndex:selectedIndex];
    }
}

The problem in my situation is that destinationViewController could be more than one view controller depending on the value of a method.
thanks for response.
 
I'm still having a problem with this.

Basically, from what I read, when touch up a cell of table, it invokes didSelectRowAtIndexPath.

So within that method, I try to target the correct segue:

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Unit *unit =  [units objectAtIndex:indexPath.row];

    switch ([unit.unit_type intValue])
    
    {
        case 1:
            
            [self performSegueWithIdentifier:@"ShowARemoteViewController" sender:sender];
            
            
            break;
            
        case 4:
            
            [self performSegueWithIdentifier:@"ShowBRemoteViewController" sender:sender];
            
            
            break;
            
        default:
            
            break;
            
    }
}

The problem is "sender" is not defined in the didSelectRowAtIndexPath argument list, and I need to sender to determine which view to load.

And then I use the prepareForSeque callback once the right segue is identified:
Code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Make sure we're referring to the correct segue
    if ([[segue identifier] isEqualToString:@"ShowARemoteViewController"]) {
        
        // Get reference to the destination view controller
        ARemoteViewController *vc = [segue destinationViewController];
        
        NSInteger selected_unit = [[self.tableView indexPathForSelectedRow] row];
        
        Unit *unit = [units objectAtIndex:selected_unit];
        NSNumber *unit_id = unit.unit_id;
        NSInteger int_val = [unit_id integerValue];
        
        [vc setUnitId:int_val];
    }
}

Unfortunately, right now I will get a compile error because the didSelectRowAtIndexPath method doesn't accept a sender object as an argument.

Anyone know how to somehow capture the sender with regard to table cells?

thanks for response
 
Just pass self as the sender.

Code:
[self performSegueWithIdentifier:@"ShowARemoteViewController" sender:[COLOR=green]self[/COLOR]];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.