I'd need to remove all columns from a table except the first two. I am Iterating over the table columns and am stuck at the part where I have to delete the column based on the index.

So far I have this:

int x;
for (x = 2; x < [table numberOfColumns]; x++) {
    [table removetablecolumn:([table column:x])]

}
有帮助吗?

解决方案

Your code should go this way:

for (NSInteger tcIndex = self.tableView.tableColumns.count-1; tcIndex >= 2; tcIndex--){
    [self.tableView removeTableColumn:[self.tableView tableColumns][tcIndex]];
}

You need to count total columns in the tableview and then remove them.

What you are doing is that iterating through number of rows, which is incorrect.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top