user2452250 user2452250 - 10 months ago 66
Objective-C Question

Delete tableview column at index

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


Answer Source

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.