iphone - UITableView with JSON help -



iphone - UITableView with JSON help -

i trying feed in json info iphone app, info coming in fine have nslog's telling me so.

the problem having trying results show in uitableview. have navigation controller underneath tab bar controller, navigation controller contains table view controller loads nib file table view connected class delegate , info source delegate.

i need categorize results sections - these being

england scotland wales n.ireland

to thought of json string using see one.

as can see json not cater sections yet implement this, need know beforehand not have amend much code later on.

ok - using stig json parser.

here listvenuesview.h (connected table view)

#import <uikit/uikit.h> #import "sbjson.h" @interface listvenuesview : uitableviewcontroller <uitableviewdelegate, uitableviewdatasource> { iboutlet uitableview *venuelist; nsmutabledictionary *jsonarray; } @property (nonatomic, retain) iboutlet uitableview *venuelist; @property (nonatomic, retain) nsmutabledictionary *jsonarray; @end

jsonarray used store json info , proper array.

and here listvenuesview.m (key areas in question)

- (void)viewdidload { [super viewdidload]; nslog(@"table view loaded"); // uncomment next line preserve selection between presentations. // self.clearsselectiononviewwillappear = no; // uncomment next line display edit button in navigation bar view controller. // self.navigationitem.rightbarbuttonitem = self.editbuttonitem; // load json info nsurl *jsonurl = [nsurl urlwithstring:@"http://www.thebigfishexperience.org.uk/sources/ajax/venue-json.php?location=peterborough"]; nsstring *jsondata = [[nsstring alloc] initwithcontentsofurl:jsonurl]; nslog(@"%@", jsondata); // convert jsondata array self.jsonarray = [jsondata jsonvalue]; nslog(@"%@", jsonarray); nslog(@"count is: %i", [self.jsonarray count]); // release nsstring , nsurl [jsonurl release]; [jsondata release]; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { // homecoming number of rows in section. homecoming [self.jsonarray count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease]; } nsmutabledictionary *dict = [self.jsonarray objectatindex: indexpath.row]; cell.textlabel.font = [uifont fontwithname:@"arial" size:15.0]; cell.textlabel.text = [dict objectforkey:@"venuename"]; cell.detailtextlabel.text = [dict objectforkey:@"venuecorddist"]; cell.accessorytype = uitableviewcellaccessorydisclosureindicator; // configure cell... homecoming cell;

also how can utilize info in cells go subview of nav controller gives me button , displays info json string particular cell has been tapped.

i think has it? not sure though first app building! expect more pleas of assistance - ha ! ;)

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { // navigation logic may go here. create , force view controller. /* detailviewcontroller *detailviewcontroller = [[detailviewcontroller alloc] initwithnibname:@"nib name" bundle:nil]; // ... // pass selected object new view controller. [self.navigationcontroller pushviewcontroller:detailviewcontroller animated:yes]; [detailviewcontroller release]; */ }

on selecting row, mentioned u, navigating view. allow assume view controller detailviewcontroller sub-class of uiviewcontroller.

in detailviewcontroller.h , declare nsdictionary object.

in detailviewcontroller.m, add

-(void)setvenuedict:(nsdictionary*)venuedict { if( _venuedict ) { [_venuedict release]; } _venuedict = [venuedict retain]; }

in parentviewcontroller, ur didselectrow.. method should this.

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { // navigation logic may go here. create , force view controller. detailviewcontroller *detailviewcontroller = [[detailviewcontroller alloc] initwithnibname:@"nib name" bundle:nil]; // ... // pass selected object new view controller. nsdictionary *dict = [self.jsonarray objectatindex: indexpath.row]; [detailviewcontroller setvenuedict:dict]; detailviewcontroller.title = [dict objectforkey:@"venuename"]; [self.navigationcontroller pushviewcontroller:detailviewcontroller animated:yes]; [detailviewcontroller release]; }

in sec view controller, u can whatever u want _venuedict.

iphone objective-c ios uitableview

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -