ios - Information on pushing to new DetailView -


this question has answer here:

does know of tutorials out there explains how push new details views. right have 2 tableviews, first tableview holds states , second tableview holds area names. second tableview want able press area , display information in detailview, i'm not sure how information detailview.

roottableviewcontroller.h

#import <uikit/uikit.h>  @interface roottableviewcontroller : uitableviewcontroller  @end 

roottableviewcontroller.m

#import "roottableviewcontroller.h" #import "secondtableviewcontroller.h"  @interface roottableviewcontroller ()  @end  @implementation roottableviewcontroller { nsmutablearray *states; }  - (id)initwithstyle:(uitableviewstyle)style { self = [super initwithstyle:style]; if (self) {     // custom initialization } return self; }  - (void)viewdidload { [super viewdidload];  states = [nsmutablearray arraywithobjects:@"alabama", @"georgia", @"tennessee", nil];  // uncomment following line preserve selection between presentations. // self.clearsselectiononviewwillappear = no;  // uncomment following line display edit button in navigation bar view controller. // self.navigationitem.rightbarbuttonitem = self.editbuttonitem; }  - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. }  #pragma mark - table view data source  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 1; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [states count]; }   - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *simpletableidentifier = @"statescell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier];  if(cell == nil) {     cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:simpletableidentifier]; }  cell.textlabel.text = [states objectatindex:indexpath.row]; return cell; } 

secondtableviewcontroller.h

#import <uikit/uikit.h>  @interface secondtableviewcontroller : uitableviewcontroller { nsmutablearray *listofstates; } @property (retain, atomic) nsmutablearray *listofstates; @property (nonatomic, strong) nsstring *statename;  @end 

secondtableviewcontroller.m

#import "secondtableviewcontroller.h" #import "roottableviewcontroller.h"  @interface secondtableviewcontroller ()  @end  @implementation secondtableviewcontroller  @synthesize listofstates = _listofstates;  - (id)initwithstyle:(uitableviewstyle)style { self = [super initwithstyle:style]; if (self) {     // custom initialization } return self; }  - (void)viewdidload { [super viewdidload];  _listofstates = [nsdictionary dictionary];   _listofstates  = @{ @"alabama":@[         @{@"area":@"albama area 1", @"description":@"alabama specs 1"},         @{@"area":@"albama area 2", @"description":@"alabama specs 2"},         @{@"area":@"albama area 3", @"description":@"alabama specs 3"},         ], @"georgia":@[         @{@"area":@"georgia area 1", @"description":@"georgia specs 1"},         @{@"area":@"georgia area 2", @"description":@"georgia specs 2"},         @{@"area":@"georgia area 3", @"description":@"georgia specs 3"}         ], @"tennessee":@[         @{@"area":@"tennessee area 1", @"description":@"tennessee specs 1"},         @{@"area":@"tennessee area 2", @"description":@"tennessee specs 2"},         @{@"area":@"tennessee area 3", @"description":@"tennessee specs 3"}         ]  };  nsarray *state = [_listofstates objectforkey:_statename];  // uncomment following line preserve selection between presentations. // self.clearsselectiononviewwillappear = no;  // uncomment following line display edit button in navigation bar view controller. // self.navigationitem.rightbarbuttonitem = self.editbuttonitem;  - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. }  #pragma mark - table view data source  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 1; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [self.state count]; }   - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath    *)indexpath { static nsstring *simpletableidentifier = @"animal2cell";  uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier]; cell.textlabel.text = [[self.state objectatindex:indexpath.row] objectforkey:@"area"];  return cell; }  -(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { [self performseguewithidentifier:@"detailsegue" sender:sender]; }  #pragma mark - navigation - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { // make sure segue name in storyboard same line if ([[segue identifier] isequaltostring:@"detailsegue"]) {     //get specs     nsindexpath *indexpath = [self.tableview indexpathforselectedrow];     nsstring *specs = [_informationspecs objectatindex:indexpath.row];      //set specs     detailviewcontroller *detailvc= (detailviewcontroller *)segue.destinationviewcontroller;     detailvc.description= [[self.state objectatindex:indexpath.row] objectforkey:@"description"]; } }  @end 

errors

secondtableviewcontroller.m:43:10: expected ':'  secondtableviewcontroller.m:58:37: no visible @interface 'nsdictionary' declares selector 'obejectforkey:'  secondtableviewcontroller.m:67:9: use of undeclared identifier 'didreceivememorywarning' 

thanks guidance.

instead of having array each state should put data because related.

list of states:

_listofstates  = @{   @"alabama":@[             @{@"area":@"albama area 1", @"description":@"alabama specs 1"},             @{@"area":@"albama area 2", @"description":@"alabama specs 2"},             @{@"area":@"albama area 3", @"description":@"alabama specs 3"},             ],   @"georgia":@[             @{@"area":@"georgia area 1", @"description":@"georgia specs 1"},             @{@"area":@"georgia area 2", @"description":@"georgia specs 2"},             @{@"area":@"georgia area 3", @"description":@"georgia specs 3"}             ],   @"tennessee":@[             @{@"area":@"tennessee area 1", @"description":@"tennessee specs 1"},             @{@"area":@"tennessee area 2", @"description":@"tennessee specs 2"},             @{@"area":@"tennessee area 3", @"description":@"tennessee specs 3"}             ]    }; 

state array:

self.state = [_listofstates objectforkey:_statename]; 

numberofrowsinsection

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return [self.state count]; } 

cellforrowatindexpath

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *simpletableidentifier = @"animal2cell";      uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier];     cell.textlabel.text = [[self.state objectatindex:indexpath.row] objectforkey:@"area"];      return cell; } 

didselectrowatindexpath

 -(void)tableview:(uitableview *)tableview                              didselectrowatindexpath:(nsindexpath *)indexpath{    [self performseguewithidentifier:@"detailsegue" sender:sender];  } 

prepareforsegue

 - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     // make sure segue name in storyboard same line     if ([[segue identifier] isequaltostring:@"detailsegue"])     {          //get specs        nsindexpath *indexpath = [self.tableview indexpathforselectedrow];        nsstring *description = [[self.state objectatindex:indexpath.row] objectforkey:@"description"];         //set specs        detailviewcontroller *detailvc= (detailviewcontroller *)segue.destinationviewcontroller;        detailvc.description= description;     } } 

demo project


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -