Adding two Table Views to the main View in Xcode

前端 未结 2 1485
天命终不由人
天命终不由人 2021-01-06 19:00

I placed two Table View\'s onto my main.storyboard. I then created two new .swift class files for them: VideoTableViewController and LinkTableViewController. How do I link t

2条回答
  •  自闭症患者
    2021-01-06 19:18

    If you want 2 tableviews in the same view controller do the following:

    1. Create a UIViewController that is a delegate to

      UITableViewDelegate, UITableViewDataSource
      
    2. Add 2 uitableviews to this view controller in the storyboard
    3. Add 2 IBOutlets for the UITableViews in your ViewController.h file like this:

      @property (nonatomic, weak) IBOutlet UITableView *tableView1;
      @property (nonatomic, weak) IBOutlet UITableView *tableView2;
      
    4. Connect the IBOutlets to these.

    5. Add the delegate functions for the tableview in the .m file somethng like this:

       - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
       {
          // Return the number of rows in the section.
          if(tableView == self.tableView1){
              return whatever1;
          }
      
          if(tableView == self.tableView2){
              return whatever2;
          }
       }
      

提交回复
热议问题