ios - Pull to refresh UITableView Data -
i have pull refresh setup. it's calling [self.tableview reloaddata]; it's not reloading parsed json info blogdata method. theres i'm missing?
my controller this:
// // artableviewcontroller.m // worldcuplive // // created adam rais on 14/06/2014. // copyright (c) 2014 adam rais. rights reserved. // #import "artableviewcontroller.h" #import "armodal.h" @interface artableviewcontroller () @end @implementation artableviewcontroller - (id)initwithstyle:(uitableviewstyle)style { self = [super initwithstyle:style]; if (self) { // custom initialization } homecoming self; } - (void)viewdidload { [super viewdidload]; self.blogpost = [[armodal alloc] init]; self.blogpost.jsonmutable = [nsmutablearray array]; (nsdictionary *post in self.blogpost.blogdata) { armodal *bp = [armodal blogpostwithhome:[[post objectforkey:@"home"] objectforkey:@"text"]]; bp.away = [[post objectforkey:@"away"] objectforkey:@"text"]; bp.result = [[post objectforkey:@"result"] objectforkey:@"text"]; bp.info = [post objectforkey:@"info"]; bp.homeimage = [[post objectforkey:@"homeimage"] objectforkey:@"src"]; [self.blogpost.jsonmutable addobject:bp]; } [self randombackgroundimage]; self.tableview.contentinset = uiedgeinsetsmake(0.0f, -10.0f, 0.0f, 0.0f); // initialize refresh command uirefreshcontrol *refreshcontrol = [[uirefreshcontrol alloc] init]; // configure refresh command [refreshcontrol addtarget:self action:@selector(refresh:) forcontrolevents:uicontroleventvaluechanged]; // configure view controller [self setrefreshcontrol:refreshcontrol]; } -(void)randombackgroundimage { uiimage *image = self.blogpost.imageui; uiimageview *imageview = [[uiimageview alloc] initwithimage:image]; self.tableview.backgroundview = imageview; self.tableview.backgroundview.layer.zposition -= 1; } - (void)refresh:(id)sender { nslog(@"refreshing"); [self.tableview reloaddata]; [self randombackgroundimage]; // end refreshing [(uirefreshcontrol *)sender endrefreshing]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } #pragma mark - table view info source - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { // homecoming number of sections. homecoming 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { // homecoming number of rows in section. homecoming [self.blogpost.jsonmutable count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"cell" forindexpath:indexpath]; // configure cell... armodal *post = [self.blogpost.jsonmutable objectatindex:indexpath.row]; nsdata *imagedata = [nsdata datawithcontentsofurl:post.jsonurl]; uiimage *image = [uiimage imagewithdata:imagedata]; cell.textlabel.text = [[[[[post.home stringbyappendingstring:@" "]stringbyappendingstring:@" "] stringbyappendingstring:post.bst] stringbyappendingstring:@" "] stringbyappendingstring:post.away]; cell.detailtextlabel.text = post.info; cell.imageview.image = image; cell.backgroundcolor = [uicolor colorwithwhite:1.000 alpha:0.000]; homecoming cell; } /* // override back upwards conditional editing of table view. - (bool)tableview:(uitableview *)tableview caneditrowatindexpath:(nsindexpath *)indexpath { // homecoming no if not want specified item editable. homecoming yes; } */ /* // override back upwards editing table view. - (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath { if (editingstyle == uitableviewcelleditingstyledelete) { // delete row info source [tableview deleterowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationfade]; } else if (editingstyle == uitableviewcelleditingstyleinsert) { // create new instance of appropriate class, insert array, , add together new row table view } } */ /* // override back upwards rearranging table view. - (void)tableview:(uitableview *)tableview moverowatindexpath:(nsindexpath *)fromindexpath toindexpath:(nsindexpath *)toindexpath { } */ /* // override back upwards conditional rearranging of table view. - (bool)tableview:(uitableview *)tableview canmoverowatindexpath:(nsindexpath *)indexpath { // homecoming no if not want item re-orderable. homecoming yes; } */ /* #pragma mark - navigation // in storyboard-based application, want little preparation before navigation - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { // new view controller using [segue destinationviewcontroller]. // pass selected object new view controller. } */ @end and modal:
// // armodal.m // worldcuplive // // created adam rais on 14/06/2014. // copyright (c) 2014 adam rais. rights reserved. // #import "armodal.h" @implementation armodal -(id)initwithhome:(nsstring *)home { self = [super init]; if (self) { _home = home; _away = nil; _result = nil; _info = nil; _homeimage = nil; } homecoming self; } +(id)blogpostwithhome:(nsstring *)home { homecoming [[self alloc] initwithhome:home]; } -(nsarray *)blogdata { nsurl *jsonurl = [nsurl urlwithstring:@"http://www.kimonolabs.com/api/2nfgfo2s?apikey=1a1f5f323969d5157af8a8be857026c2"]; nsdata *jsondata = [nsdata datawithcontentsofurl:jsonurl]; nserror *jsonerror = nil; nsdictionary *jsondictionary = [nsjsonserialization jsonobjectwithdata:jsondata options:0 error:&jsonerror]; nsarray *jsonarray = [[jsondictionary objectforkey:@"results"] objectforkey:@"collection1"]; if (blogdata == nil) { blogdata = jsonarray; } homecoming blogdata; } -(nsurl *)jsonurl { homecoming [nsurl urlwithstring:self.homeimage]; } -(nsstring *)bst { nsstring *sentence = self.result; nsstring *word = @"-"; nsstring *wordtwo = @"00.00"; nsstring *wordthree = @"01.00"; nsmutablearray *bstarray = [nsmutablearray array]; if ([sentence rangeofstring:word].location != nsnotfound) { nslog(@"found string"); [bstarray addobject:sentence]; } else if ([sentence rangeofstring:wordtwo].location != nsnotfound) { nslog(@"time 23:00"); [bstarray addobject:@"23:00"]; } else if ([sentence rangeofstring:wordthree].location != nsnotfound) { nslog(@"time 00:00"); [bstarray addobject:@"00:00"]; } else { float floatone = [sentence floatvalue]; float floatfinal = floatone - 1.000000; nsstring *str = [nsstring stringwithformat:@"%f", floatfinal]; nsstring *bstfinal = [str substringtoindex:[str length] - 4]; [bstarray addobject:bstfinal]; } homecoming [bstarray objectatindex:0]; } -(uiimage *)imageui { nsarray *imagearray = @[[uiimage imagenamed:@"algeria"],[uiimage imagenamed:@"argentina"],[uiimage imagenamed:@"australia"],[uiimage imagenamed:@"belgium"],[uiimage imagenamed:@"bosnia-herzegovina"],[uiimage imagenamed:@"switzerland"],[uiimage imagenamed:@"uruguay"],[uiimage imagenamed:@"usa"],[uiimage imagenamed:@"brazil"],[uiimage imagenamed:@"cameroon"],[uiimage imagenamed:@"chile"],[uiimage imagenamed:@"colombia"],[uiimage imagenamed:@"costa rica"],[uiimage imagenamed:@"côte d'ivoire"],[uiimage imagenamed:@"croatia"],[uiimage imagenamed:@"ecuador"],[uiimage imagenamed:@"england"],[uiimage imagenamed:@"france"],[uiimage imagenamed:@"germany"],[uiimage imagenamed:@"ghana"],[uiimage imagenamed:@"greece"],[uiimage imagenamed:@"honduras"],[uiimage imagenamed:@"iran"],[uiimage imagenamed:@"italy"],[uiimage imagenamed:@"japan"],[uiimage imagenamed:@"mexico"],[uiimage imagenamed:@"netherlands"],[uiimage imagenamed:@"nigeria"],[uiimage imagenamed:@"portugal"],[uiimage imagenamed:@"russia"],[uiimage imagenamed:@"south korea"],[uiimage imagenamed:@"spain"]]; int random = arc4random_uniform(imagearray.count); homecoming [imagearray objectatindex:random]; } @end
when phone call -[uitableview reloaddata] method telling tableview refresh ints content based on source gave him, doesnt alter source. in cases refresh datasource , need refresh uitableview phone call -[uitableview reloaddata]. need first refresh info , refresh view, view uses new data.
use the same way got info modal refresh it.
self.blogpost.jsonmutable = [nsmutablearray array]; (nsdictionary *post in self.blogpost.blogdata) { armodal *bp = [armodal blogpostwithhome:[[post objectforkey:@"home"] objectforkey:@"text"]]; bp.away = [[post objectforkey:@"away"] objectforkey:@"text"]; bp.result = [[post objectforkey:@"result"] objectforkey:@"text"]; bp.info = [post objectforkey:@"info"]; bp.homeimage = [[post objectforkey:@"homeimage"] objectforkey:@"src"]; [self.blogpost.jsonmutable addobject:bp]; } then execute -[uitableview reloaddata], going refresh using refreshed info got modal.
if need else, comment.
ios objective-c uitableview
No comments:
Post a Comment