Table View Controller each row connected to another view controller

I am trying to develop a Table View Controller where rows are associated with several View Controllers(TextField, TextView, TableView, DatePicker, ImageView, etc.).

So, if I click on any line, it should open Intermediate Viewand place the corresponding controller in the usual place where the rest of the thing will be the same for the entire controller. Suppose I clicked on a row where it is indexed in a TableView. When he opens the intermediate controller, he must put the table view in a common container, this table view must come from one TableView controller for all other tables.

I am new to ios and cannot design it.

What is the best way to develop it? How to implement this?

Root table view

enter image description here

+4
1

, Storyboard . , . UITableViewCell.

segue .

enter image description here

UITableView. -tableView:didSelectRowAtIndexPath: .

:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.row) {
        case 0:
            [self performSegueWithIdentifier:@"BasicCoreDataSegue" sender:self];
            break;

        default:
            break;
    }
}

, , , , BasicCoreDataSegue segue Storyboard, .

, didSelectRowAtIndexPath .

, , , :

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([[segue identifier] isEqualToString:@"BasicCoreDataSegue"]) {
        // Get reference to the destination view controller
        TextViewController *vc = [segue destinationViewController];
        vc.textView.text = "Hello";
    }
} 

:

. , didSelectRowAtIndexPath segue.

[self.tableView indexPathForSelectedRow], prepareForSegue.

:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        [self performSegueWithIdentifier:@"BasicCoreDataSegue" sender:self];
}

, prepareForSegue, .

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // Get the new view controller using [segue destinationViewController].

        // You can get selected row using below line
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        // Pass the selected object to the new view controller.
        if ([[segue identifier] isEqualToString:@"BasicCoreDataSegue"]) {
            // Get reference to the destination view controller
            IntermediateController *vc = [segue destinationViewController];
            vc.selectedIndex = indexPath.row;
        }
    }

selectedIndex , , .

-viewDidLoad() , , , .

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                         bundle: nil];

TextViewController *controller = (TextViewController*)[storyBoard 
                    instantiateViewControllerWithIdentifier: @"TextViewControllerId"];

[self.topView addSubview:controller.view];
+5

Source: https://habr.com/ru/post/1569961/


All Articles