iphone - Grouped Table View Obj-C -


i followed tutorial here , wondering how make table appear grouped.

ex:

group1 contains subview 1 , subview two

group2 contains subview three

i switched type in interface builder shows 1 group.

thanks, adam

sidenote* new @ objective c, hence tutorial.

edit

i thought might helpful put piece of code

#import "rootviewcontroller.h" #import "subviewonecontroller.h" #import "subviewtwocontroller.h"   @implementation rootviewcontroller   #pragma mark - #pragma mark view lifecycle  -(void)awakefromnib {     views = [[nsmutablearray alloc] init];  subviewonecontroller *subviewonecontroller = [[subviewonecontroller alloc] init]; subviewtwocontroller *subviewtwocontroller = [[subviewtwocontroller alloc] init];  //subview 1      subviewonecontroller.title = @"subview one";     [views addobject:[nsdictionary dictionarywithobjectsandkeys:                       @"subview one",           @"title",                       subviewonecontroller,     @"controller",                       nil]];     [subviewonecontroller release];  //subview 2  subviewonecontroller = [[subviewonecontroller alloc] init]; subviewonecontroller.title = @"subview two"; [views addobject:[nsdictionary dictionarywithobjectsandkeys:                   @"subview two",           @"title",                   subviewtwocontroller,     @"controller",                   nil]]; [subviewonecontroller release];  //subview 3  subviewonecontroller = [[subviewonecontroller alloc] init]; subviewonecontroller.title = @"subview three"; [views addobject:[nsdictionary dictionarywithobjectsandkeys:                   @"subview three",         @"title",                   subviewonecontroller,     @"controller",                   nil]]; [subviewonecontroller release];  uibarbuttonitem *temporarybarbuttonitem = [[uibarbuttonitem alloc] init]; temporarybarbuttonitem.title = @"back"; self.navigationitem.backbarbuttonitem = temporarybarbuttonitem; [temporarybarbuttonitem release];  self.title = @"basic navigation"; }  - (void)didreceivememorywarning { [super didreceivememorywarning]; }  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 2; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [views count]; } // //i think goes somewhere in here // - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {  static nsstring *cellidentifier = @"cell";  uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) {     cell = [[uitableviewcell alloc] initwithstyle:uitableviewstylegrouped reuseidentifier:cellidentifier]; }  cell.text = [[views objectatindex:indexpath.row] objectforkey:@"title"];   return cell; }  - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { uiviewcontroller *targetviewcontroller = [[views objectatindex:indexpath.row] objectforkey:@"controller"]; [[self navigationcontroller] pushviewcontroller:targetviewcontroller animated:yes]; }  - (void)dealloc { [views dealloc]; [super dealloc]; }   @end 

ok correct go cellforrowatindexpath: looking like:

if ([indexpath section] == 0) { //stuff first section. }

if ([indexpath section] == 1) { //stuff second section. }

you need deal how configuring cell array. sections row numbers start 0. same thing didselectrowatindexpath: if don't deal section set cell.text end with

subview one

subview two

subview one

i recommend getting iphone programming (the big nerd ranch guide)


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -