From 1d8eab5abc23171fd947f885f10d4f747b5503d3 Mon Sep 17 00:00:00 2001 From: Denys Telezhkin Date: Sun, 12 Oct 2014 16:17:09 +0300 Subject: [PATCH] add ability to set header/footer for selected section --- .travis.yml | 4 +--- DTModelStorage/Memory/DTMemoryStorage.h | 20 +++++++++++++++++++- DTModelStorage/Memory/DTMemoryStorage.m | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e53dacda..32d6de77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,7 @@ language: objective-c before_install: - sudo gem install cocoapods --no-document --quiet -- sudo gem install ios_ci --no-document --quiet -- brew install ios-sim - export LANG=en_US.UTF-8 - cd DTModelStorageTests -script: ios_ci cedar --source-root $TRAVIS_BUILD_DIR/DTModelStorageTests --workspace DTModelStorageTests.xcworkspace --scheme Tests --build-path Build/Products +script: rake diff --git a/DTModelStorage/Memory/DTMemoryStorage.h b/DTModelStorage/Memory/DTMemoryStorage.h index ebd69dfc..cc831b14 100644 --- a/DTModelStorage/Memory/DTMemoryStorage.h +++ b/DTModelStorage/Memory/DTMemoryStorage.h @@ -173,12 +173,30 @@ - (void)setSupplementaries:(NSArray *)supplementaryModels forKind:(NSString *)kind; /** - Set header models for UITableView sections. `DTSectionModel` objects are created automatically, if they don't exist already. Pass nil or empty array to this method to clear all section header models. + Set header models for sections. `DTSectionModel` objects are created automatically, if they don't exist already. Pass nil or empty array to this method to clear all section header models. @param headerModels Section header models to use. */ - (void)setSectionHeaderModels:(NSArray *)headerModels; +/** + Set header model for section. `DTSectionModel` object is created automatically, if it doesn't exist already. + + @param headerModel Section header model to use. + + @param sectionNumber Number of the section + */ +- (void)setSectionHeaderModel:(id)headerModel forSectionIndex:(NSUInteger)sectionNumber; + +/** + Set footer model for section. `DTSectionModel` object is created automatically, if it doesn't exist already. + + @param footerModel Section header model to use. + + @param sectionNumber Number of the section + */ +- (void)setSectionFooterModel:(id)footerModel forSectionIndex:(NSUInteger)sectionNumber; + /** Set footer models for sections. `headerKind` property is used to define kind of header supplementary. `DTSectionModel` objects are created automatically, if they don't exist already. Pass nil or empty array to this method to clear all section footer models. diff --git a/DTModelStorage/Memory/DTMemoryStorage.m b/DTModelStorage/Memory/DTMemoryStorage.m index c7ca47e7..0a11fbca 100644 --- a/DTModelStorage/Memory/DTMemoryStorage.m +++ b/DTModelStorage/Memory/DTMemoryStorage.m @@ -89,6 +89,24 @@ - (id)supplementaryModelOfKind:(NSString *)kind forSectionIndex:(NSUInteger)sect return [sectionModel supplementaryModelOfKind:kind]; } +-(void)setSectionHeaderModel:(id)headerModel forSectionIndex:(NSUInteger)sectionNumber +{ + NSAssert(self.supplementaryHeaderKind, @"supplementaryHeaderKind property was not set before calling setSectionHeaderModel: forSectionIndex: method"); + + DTSectionModel * section = [self sectionAtIndex:sectionNumber]; + + [section setSupplementaryModel:headerModel forKind:self.supplementaryHeaderKind]; +} + +-(void)setSectionFooterModel:(id)footerModel forSectionIndex:(NSUInteger)sectionNumber +{ + NSAssert(self.supplementaryHeaderKind, @"supplementaryFooterKind property was not set before calling setSectionFooterModel: forSectionIndex: method"); + + DTSectionModel * section = [self sectionAtIndex:sectionNumber]; + + [section setSupplementaryModel:footerModel forKind:self.supplementaryFooterKind]; +} + -(id)headerModelForSectionIndex:(NSInteger)index { NSAssert(self.supplementaryHeaderKind, @"supplementaryHeaderKind property was not set before calling headerModelForSectionIndex: method");