UITableViewController accessing static cells programmatically issue

后端 未结 6 1451
孤独总比滥情好
孤独总比滥情好 2021-01-05 23:41

Say I have a table with 10 static cells in it, is there a way to select a certain cell programmatically?

I\'ve tried this

UITableViewCell *cell = [se         


        
6条回答
  •  猫巷女王i
    2021-01-06 00:24

    To access statically created cells, try this:

    UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
    

    This works for static cells. So, if you're in the...

    - (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
         UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
    
        return cell;
    
    }
    

    ... delegate, you can access all statically configured cells using the above declaration. From there, you can do what ever you want with "cell".

    I had a ViewController that had two UITableViews on it. One of them had cells defined statically, with a Storyboard, and the other had cells defined dynamically using code. Given I was using the same ViewController as delegate for both tables, I needed to prevent new cells from being created where cellForRowAtIndexPath was being called where cells had already been created.

    In your case, you need to gain programmatic access to your cells.

    Have fun.

提交回复
热议问题