The first scene of the project is a dynamic cell view, as shown below. I have given this an identifier so I can refernce it in the code.
I have created a second grouped section from within the code which displays as expected. When a user clicks on the first cell it moves to one particular scene, however the second cell also goes to the same scene.
How can I give the second cell a separate identifier so I can then create a segue to a different scene? The second cell doesn't appear in the Storyboard so I can't give it one that way.
The code I have for this scene at the moment is below:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize testLocation;
- (void)viewDidLoad
{
testLocation = @"Washington, Dulles";
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark - Table View Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // Default is 1 if not implemented
{
return 2;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; // fixed font style. use custom view (UILabel) if you want something different
{
if (section == 0) {
return @"Choose Test Location:";
}
else {
return @"Choose Test Type:";
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
if (section == 0) {
return 1;
}
else {
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *serverLocCell = [tableView dequeueReusableCellWithIdentifier:@"serverLocation"];
switch (indexPath.section) {
case 0:
serverLocCell.textLabel.text = testLocation;
serverLocCell.detailTextLabel.text = @"Change";
break;
case 1:
serverLocCell.textLabel.text = @"Speed Test";
serverLocCell.detailTextLabel.text = @"Change";
break;
default:
break;
}
return serverLocCell;
}
@end
In the storyboard editor, create the two segues you want to use — but make them segue from one controller to the next, NOT from the table view. Do it at the controller level. Give each segue a specific and different name.
Implement didSelectRowAtIndexPath
so you know when the user selects a cell in the table. Depending on the section (or row) in the index path, programmatically fire the segue.