OK I came up with a solution according to the storyboard that I like.
Example:
In my view of the table, 2 sections, grouped and cells are a dynamic prototype. Section 0 contains a single line / UITableViewCell, and I do not want it to jump. Section 1 contains several cells that I want to call, and I will go on to the details.
In the storyboard:
- I removed segue by linking tableviewcell to the destination view controller.
- I made a βgenericβ segue related to the source view controller directly with the destination view controller.
- In the attributes on segue I set the identifier ("EditTimePeriod") and set the type to Push (I assume that Modal will work the same way).
In the source view controller:
In the prepareForSegue method, I processed both the regular "AddTimePeriod" segue I element that was transferred from my UIBarButtonItem (Add) and the "generic" (vc β vc) "EditTimePeriod" segue.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // handle the click of the 'Add' bar button item if([segue.identifier isEqualToString:@"AddTimePeriod"]) { TimePeriodViewController* tpvc = (TimePeriodViewController*)segue.destinationViewController; tpvc.delegate = self; // database & entity stuff for adding the new one to the mOC, etc } // handle the click of one of the 'editable' cells - if([segue.identifier isEqualToString:@"EditTimePeriod"]) { TimePeriodViewController* tpvc = (TimePeriodViewController*)segue.destinationViewController; tpvc.delegate = self; TimePeriod * newTP = [self.timePeriodArray objectAtIndex:self.tableView.indexPathForSelectedRow.row]; tpvc.timePeriod = newTP; } }
Then I applied the tableView: didSelectRowAtIndexPath method and placed my condition here. If the selected row was outside the zero section, I manually called EditTimePeriod segue, defining the sender as the selected tableviewcell:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(self.tableView.indexPathForSelectedRow.section!=0){ [self performSegueWithIdentifier:@"EditTimePeriod" sender:[tableView cellForRowAtIndexPath:indexPath]]; } [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; return; }
it would be nice to encode the cell in section 0 so that it is not selected in the first place! Hope this helps.
**, and then after 5 minutes I took another look and realized that I could just move the data from section 0 to the section header, which is more intuitive and was not used in any case. leaving the construct open for standard exit from each tableview table without any condition / check. It was a good exercise anyway though :)
cafeakashic May 02 '12 at 7:04 2012-05-02 07:04
source share