From c6fb707b2dc4e0963501ee9349ae621f2d340441 Mon Sep 17 00:00:00 2001 From: Roman Efimov Date: Wed, 13 Mar 2013 15:53:17 -0500 Subject: [PATCH] Add section index --- RETableViewManager/RETableViewManager.h | 12 ++++++------ RETableViewManager/RETableViewManager.m | 23 +++++++++++++++++------ RETableViewManager/RETableViewSection.h | 9 +++++++++ RETableViewManager/RETableViewSection.m | 11 +++++++++++ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/RETableViewManager/RETableViewManager.h b/RETableViewManager/RETableViewManager.h index 2a01f6e..79baa01 100644 --- a/RETableViewManager/RETableViewManager.h +++ b/RETableViewManager/RETableViewManager.h @@ -105,20 +105,20 @@ - (RETableViewSection *)addSection:(RETableViewSection *)section; - (void)addSectionsFromArray:(NSArray *)array; -- (RETableViewSection *)insertSection:(id)section atIndex:(NSUInteger)index; +- (RETableViewSection *)insertSection:(RETableViewSection *)section atIndex:(NSUInteger)index; - (void)insertSections:(NSArray *)sections atIndexes:(NSIndexSet *)indexes; ///----------------------------- /// @name Removing Sections ///----------------------------- -- (void)removeSection:(id)section; +- (void)removeSection:(RETableViewSection *)section; - (void)removeAllSections; -- (void)removeSectionIdenticalTo:(id)section inRange:(NSRange)range; -- (void)removeSectionIdenticalTo:(id)section; +- (void)removeSectionIdenticalTo:(RETableViewSection *)section inRange:(NSRange)range; +- (void)removeSectionIdenticalTo:(RETableViewSection *)section; - (void)removeSectionsInArray:(NSArray *)otherArray; - (void)removeSectionsInRange:(NSRange)range; -- (void)removeSection:(id)section inRange:(NSRange)range; +- (void)removeSection:(RETableViewSection *)section inRange:(NSRange)range; - (void)removeLastSection; - (void)removeSectionAtIndex:(NSUInteger)index; - (void)removeSectionsAtIndexes:(NSIndexSet *)indexes; @@ -127,7 +127,7 @@ /// @name Replacing Sections ///----------------------------- -- (void)replaceSectionAtIndex:(NSUInteger)index withSection:(id)section; +- (void)replaceSectionAtIndex:(NSUInteger)index withSection:(RETableViewSection *)section; - (void)replaceSectionsAtIndexes:(NSIndexSet *)indexes withSections:(NSArray *)sections; - (void)replaceSectionsInRange:(NSRange)range withSectionsFromArray:(NSArray *)otherArray range:(NSRange)otherRange; - (void)replaceSectionsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray; diff --git a/RETableViewManager/RETableViewManager.m b/RETableViewManager/RETableViewManager.m index a3bc367..19ef788 100644 --- a/RETableViewManager/RETableViewManager.m +++ b/RETableViewManager/RETableViewManager.m @@ -201,27 +201,33 @@ - (RETableViewSection *)addSection:(RETableViewSection *)section { + section.tableViewManager = self; [_sections addObject:section]; return section; } - (void)addSectionsFromArray:(NSArray *)array { + for (RETableViewSection *section in array) + section.tableViewManager = self; [_sections addObjectsFromArray:array]; } -- (RETableViewSection *)insertSection:(id)section atIndex:(NSUInteger)index +- (RETableViewSection *)insertSection:(RETableViewSection *)section atIndex:(NSUInteger)index { + section.tableViewManager = self; [_sections insertObject:section atIndex:index]; return section; } - (void)insertSections:(NSArray *)sections atIndexes:(NSIndexSet *)indexes { + for (RETableViewSection *section in sections) + section.tableViewManager = self; [_sections insertObjects:sections atIndexes:indexes]; } -- (void)removeSection:(id)section +- (void)removeSection:(RETableViewSection *)section { [_sections removeObject:section]; } @@ -231,12 +237,12 @@ [_sections removeAllObjects]; } -- (void)removeSectionIdenticalTo:(id)section inRange:(NSRange)range +- (void)removeSectionIdenticalTo:(RETableViewSection *)section inRange:(NSRange)range { [_sections removeObjectIdenticalTo:section inRange:range]; } -- (void)removeSectionIdenticalTo:(id)section +- (void)removeSectionIdenticalTo:(RETableViewSection *)section { [_sections removeObjectIdenticalTo:section]; } @@ -251,7 +257,7 @@ [_sections removeObjectsInRange:range]; } -- (void)removeSection:(id)section inRange:(NSRange)range +- (void)removeSection:(RETableViewSection *)section inRange:(NSRange)range { [_sections removeObject:section inRange:range]; } @@ -271,18 +277,23 @@ [_sections removeObjectsAtIndexes:indexes]; } -- (void)replaceSectionAtIndex:(NSUInteger)index withSection:(id)section +- (void)replaceSectionAtIndex:(NSUInteger)index withSection:(RETableViewSection *)section { + section.tableViewManager = self; [_sections replaceObjectAtIndex:index withObject:section]; } - (void)replaceSectionsAtIndexes:(NSIndexSet *)indexes withSections:(NSArray *)sections { + for (RETableViewSection *section in sections) + section.tableViewManager = self; [_sections replaceObjectsAtIndexes:indexes withObjects:sections]; } - (void)replaceSectionsInRange:(NSRange)range withSectionsFromArray:(NSArray *)otherArray range:(NSRange)otherRange { + for (RETableViewSection *section in otherArray) + section.tableViewManager = self; [_sections replaceObjectsInRange:range withObjectsFromArray:otherArray range:otherRange]; } diff --git a/RETableViewManager/RETableViewSection.h b/RETableViewManager/RETableViewSection.h index 52079f2..6d57f0c 100644 --- a/RETableViewManager/RETableViewSection.h +++ b/RETableViewManager/RETableViewSection.h @@ -25,6 +25,8 @@ #import +@class RETableViewManager; + /** Table view section. */ @@ -55,6 +57,13 @@ */ @property (strong, readwrite, nonatomic) UIView *footerView; +@property (weak, readwrite, nonatomic) RETableViewManager *tableViewManager; + +/** + Section index in UITableView. + */ +@property (assign, readonly, nonatomic) NSUInteger index; + ///----------------------------- /// @name Creating and Initializing a RETableViewSection ///----------------------------- diff --git a/RETableViewManager/RETableViewSection.m b/RETableViewManager/RETableViewSection.m index 5add239..6ef9d6c 100644 --- a/RETableViewManager/RETableViewSection.m +++ b/RETableViewManager/RETableViewSection.m @@ -24,6 +24,7 @@ // #import "RETableViewSection.h" +#import "RETableViewManager.h" @implementation RETableViewSection @@ -105,6 +106,16 @@ return self; } +#pragma mark - +#pragma mark Reading information + +- (NSUInteger)index +{ + + RETableViewManager *tableViewManager = self.tableViewManager; + return [tableViewManager.sections indexOfObject:self]; +} + #pragma mark - #pragma mark Managing items