How to programmatically create a button-transition in the prototype cell, with the possibility of returning in the future (Navigation Controller)? There is an idea to put a UIButton in a cell, set a tag and then manipulate it, but it seems to me wrong in this case) There must be something standard for the prototype cell as shown in the screenshot

It is worth noting that the button press event needs to be processed (I will transfer data to the next form, indicating what to show) Creating a kind of tree

Cell creation:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{ UITableViewCell *cell; cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; // ячейка if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; } // Выводим, обращаясь к тэгам NSError *error = nil; id object = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingAllowFragments error:&error]; UILabel *firstLabel; firstLabel = [cell.contentView viewWithTag:1001]; firstLabel.text = [namesDepart[indexPath.row] objectForKey:@"Name"]; UILabel *secondLabel; secondLabel = [cell.contentView viewWithTag:1002]; secondLabel.text = @""; return cell; } 

enter image description here

In the screenshot below, such scrolling does not work, you can specify the Initial View Controller for the Navigator Controller and then the push will work, however you need the view controller connect to be the first screen loaded and that it is without navigation

 - (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath { ViewControllerSecondTable *viewControllerSecondTable = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerSecondTable"]; [self.navigationController pushViewController:viewControllerSecondTable animated:YES]; } 

enter image description here

  • Can you clarify why exactly this screen transition order? If the matter is in the navigation bar on the first screen, then you can simply hide it during screen initialization (if necessary, show it again) and make the usual navigation. - Nerevarys

1 answer 1

Native cell click handling method:

 - (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath { ... } 

And inside this method, push to the controller you need:

 ViewController2 *vc2 = [[ViewController2 alloc] init]; [self.navigationController pushViewController:vc2 animated:YES]; 
  • added a question to the question, due to the complexity of the connections (screenshot explaining why it is necessary so), push does not work - StriBog
  • Connect your Table controller and Second controller in the storyboard and select the desired connection type. - Vitali Eller