Question

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])]

}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top