how to clear all the rows of uitableview

前端 未结 8 678
半阙折子戏
半阙折子戏 2021-01-02 23:32

I added a button on the uinavigationbar I want to use it to clear all the rows of uitablview

How can I do that?

8条回答
  •  失恋的感觉
    2021-01-02 23:59

    What do you exactly mean by clearing the row? Do you still want them to be there, but without text? If yes, here's this code:

       UITableViewCell *cell;
    
        NSIndexPath *index;
    
            for (int i = 0 ; i < count; i++) {
                index = [NSIndexPath indexPathForRow:i inSection:0];
                cell = [tableView cellForRowAtIndexPath:index];
                cell.textLabel.text = @"";
            }
    

    If you want to delete them, you can use this code:

    [uiTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationFade];
    

提交回复
热议问题