ios - Testing UITableView's section footer -


trying test uisegmentedcontrol in uitableview, created in uitableviewdelegate method:

-(uiview *)tableview:(uitableview *)tableview viewforfooterinsection:(nsinteger)section {     if (section == 0) {         uiview *container = [[uiview alloc]initwithframe:cgrectmake(0, 0, tableview.frame.size.width, [self tableview:tableview heightforfooterinsection:section])];         [self.segmentedcontrol setcenter:container.center];         [container addsubview:self.segmentedcontrol];         return container;     } else {         return [super tableview:tableview viewforfooterinsection:section];     } } 

in test class:

-(void)testsegmentedcontrol {     mytableviewcontroller *viewcontroller = [[mytableviewcontroller alloc]initwithnibname:@"mytableviewcontroller" bundle:nil];     [viewcontroller.tableview reloaddata];      // getting footer via delegate cheating imo.     uitableviewheaderfooterview *footer =  [viewcontroller.tableview footerviewforsection:0];     uisegmentedcontrol *segmentcontrol = footer.subviews[0];     // stuff segmentcontrol check tableview.     [viewcontroller.tableview reloaddata]; } 

i'm manipulating uisegmentedcontrol via global property (viewcontroller.segmentedcontrol) , calling [viewcontroller.tableview reloaddata] update state of uitableviewcells. seems me getting footer [viewcontroller.tableview footerviewforsection:0] correct way test. guidance appreciated.

edit:

as suggested john rodgers, i've tried dequeuing uitableviewheaderfooterview we'd in cellforrowatindexpath:

-(uiview *)tableview:(uitableview *)tableview viewforfooterinsection:(nsinteger)section {     if (section == 0) {         uitableviewheaderfooterview *footer = [tableview dequeuereusableheaderfooterviewwithidentifier:self.footerreuseid];         if (footer == nil) {             footer = [[uitableviewheaderfooterview alloc]initwithreuseidentifier:self.footerreuseid];         }         if (![footer.subviews containsobject:self.segmentedcontrol]) {             [footer addsubview:self.segmentedcontrol];         }         return footer;     } else {         return [super tableview:tableview viewforfooterinsection:section];     } } 

no improvement in test method:

-(void)testsegmentedcontrol {     mytableviewcontroller *viewcontroller = [[mytableviewcontroller alloc]initwithnibname:@"mytableviewcontroller" bundle:nil];     [viewcontroller.tableview reloaddata];     uitableviewheaderfooterview *footer1 = (uitableviewheaderfooterview *)[viewcontroller.tableview dequeuereusableheaderfooterviewwithidentifier:viewcontroller.footerreuseid];     uitableviewheaderfooterview *footer2 = [viewcontroller.tableview footerviewforsection:0];     // break point shows footer1 , footer2 nil. } 

the problem you're having here, footerviewforsection uitableview method that's used provide view section.

you're going have dequeue reusable uitableviewheaderfooterview in order test in test class:

uitableviewheaderfooterview *footer = [tableview dequeuereusableheaderfooterviewwithidentifier:mysectionfooterviewidentifier]; 

this should using in footerviewforsection method provide table view, you're dequeueing in test class instead.

hope helps!

~ j


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -