Apple's documentation on UITableView discusses how to add/edit/delete rows, but it doesn't discuss adding/editing/deleting sections is detail, specially with respect to the UI. In case of add/delete rows, you can apply "add" and "delete" styles on the row using:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
However, there is no such method for sections (that i know of), which can be used to show visual controls to the user for adding "+" or deleting "-" sections. I can add a new section using the logic used for new row, however, I'm not sure how to go about deleting the whole section (or allowing the user to edit section e.g. section heading). How should i go about deleting the whole section?
Background: I'm working on a Core Data based application. I have a one to many relationship between entities.
Entity r (root) <-->> Entity p (parent),
Entity p (parent) <-->> Entity c (child)
When user creates a parent record (entity p), fixed set of child records are automatically created (entity c). In the UI, I'm showing basic information of parent (entity p) in the header e.g. title, and the associated child records (entity c) as section rows, and some summary in the footer. For some logical reasons, i can't opt for d开发者_如何学JAVArill-down approach (to avoid adding/removing sections).
Edited:
Since you can define custom views for sections, your best bet is to replace the existing one with your own UIView which, when swiped (using gestures) would delete the section. You could probably imitate that red delete button to the right, or you could just have a UIAlertView with confirmation when the user swipes on a section.
You'd use tableView:deleteSections:withRowAnimation: to delete the section.
The following SO question delves into the subject: UITableView: deleting sections with animation
Was:
Firstly,
// UITableView.h:311...
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
Secondly,
UIKIT_EXTERN_CLASS @interface UITableView : UIScrollView <NSCoding> {
// ...
NSInteger _swipeToDeleteSection;
精彩评论