iPad: Iterate over every cell in a UITableView?

后端 未结 7 1922
眼角桃花
眼角桃花 2020-12-08 19:37

iPad: Iterate over every cell in a UITableView?

7条回答
  •  孤城傲影
    2020-12-08 19:56

    Assuming a variable myTableView exists and its delegate and data source are both set:

    UITableViewCell *cell;
    NSIndexPath indexPath = [[NSIndexPath indexPathForRow:0 inSection:0];
    for(indexPath.section = 0; indexPath.section < [myTableView numberOfSections]; ++indexPath.section)
    {
        for(indexPath.row = 0; indexPath.row < [myTableView numberOfRowsInSection:indexPath.section]; ++indexPath.row)
        {
            cell = [myTableView cellForRowAtIndexPath:indexPath];
            // do something with this cell
        }
    }
    

提交回复
热议问题