开发者

Delete tableview section header view

I have a tableview with 3 sections / 3 customs section header view...

After I delete a row in one of this section and if the section come empty, how I can delete the se开发者_如何学JAVAction header view.

Thanks


One of the approaches could be to maintain flags as to whether the section has become empty and return zero height for that section's header and footer and then execute reloadSections:withRowAnimation: when the only row in section is deleted.

This is certainly better when you have section specific customizations which would become tricky to handle if we were to remove the section from our model. If there are no customizations as such, you could go about maintaining an array of arrays. Once the row array is emptied, you can discard the section from the sections array. This will reflect on reloadData.

In either case, you will need to affect the model to change the view.


what you can do after you delete the row is call the method -(void)reloadData. If you are already doing this, you need to update your datasource to indicate that the row has been deleted and in - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView you need to check that. Let me know if that helps!


One way I have dealt with this problem is implementing the section title like such:

-(NSString*) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

    return ([[allData objectForKey:[keys objectAtIndex:section]] count] > 0) ? [keys objectAtIndex:section]:@"";
}

This just checks that the array of objects for that section actually has something if it does it returns the name of the section if not it returns an empty string which hides the header title.

The table view does need to be updated for the change to come into effect, also I was a dictionary full of arrays and an array full of the dictionary keys. but something similar could be easily implemented. This method allows for insertion back into that section without having to re-instantiate an array.

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜