Can someone tell me how to assign a interface to a table view element, using storyboards? I’m making a medical calculator that has different calculators for every equation, and I need help making code that points a element to push to another interface. This is because for every equation, there are different fields to fill out (such as age, oxygen levels, whether someone has diabetes or not, height, etc.) Not every equation needs the same fields.
I have tried doing this:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Deselect row
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// Declare the view controller
UIViewController *anotherVC = nil;
// Determine the row/section on the tapped cell
switch (indexPath.section) {
case 0:
switch (indexPath.row) {
case 0: {
// initialize and allocate a specific view controller for section 0 row 0
anotherVC = [[BmiViewController alloc] init];
break;
}
case 1: {
// initialize and allocate a specific view controller for section 0 row 1
/anotherVC = [[AaOxygenGradientViewController alloc] init];
break;
}
}
break;
}
}
But after doing this, it refers back to what was originally in the storyboard document (which is empty because I have created the interface programmicatally), instead of showing my test alert popup.
Also, is it possible to maybe make a bunch of table view cells, then have every one segue to every other view controller in the storyboard?
Thanks a lot in advance!
First, you are running
deselectCellAtIndexPath? What is the reason for this? If you are just trying to remove the blue highlight then it’s better to change theUITableViewCellSelectionStyle(or something like this) of the cell.I’m not sure what you’re asking for the first part but for the segue part then yes.
In
Storyboardset up the segues from thetableViewControllerto each other VC that you want to segue to and give them all sensible identifiers.i.e. medicalCalulatorSegue
graphSegue
userDetailsSegue
etc…
Then in your
didSelectmethod you will have something like…This will then segue to each of the different view controllers depending on which cell is selected.
The reason for not deselcting the cell is that in your method
prepareForSegueyou can then still access theindexPathof the selected cell…