How to programmatically turn ViewController into a UITableViewController

后端 未结 1 807
感动是毒
感动是毒 2021-01-29 13:30

I currently have a MatchCenterViewController that I want to programmatically turn into a UITableViewController. I\'ve attempted to do so below based on tutorials I\

相关标签:
1条回答
  • 2021-01-29 14:00

    As a minimum, you need to implement the following methods

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    

    And you need to set the delegate and datasource, typically in viewDidLoad

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        self.tableView.dataSource = self;
        self.tableView.delegate = self;
    }
    

    Also, you need an IBOutlet to the table view if the table view was created in storyboard, or a property for the table view, if the table view was created in code.

    0 讨论(0)
提交回复
热议问题