objective c - How to make tableView reload if Session complete download Data for it? -



objective c - How to make tableView reload if Session complete download Data for it? -

my application fetching info url. utilize nsurlsession download info asynchronously. info rearranging , displaying in tableview. need ready on viewdidload.

the problem , asynchronous mean info preparation 1 sec slower speed of main thread.

view loadded , tableview got 0 info , , display 0 data.

1 sec later, 2nd thread running completion handler , , storing info net @property well.

but tableview loadded nil display , , need reload.

1st solution

yes , can prepare problem , phone call [self.delegate.tableview reloaddata]; within gdc main thread (which within completion handler) seem violating mvc pattern!.

2nd solution

so need figure out sec solution , allow viewcontroller implement delegate own model , code within gdc [self reloadtableviewdata]; instead of [self.delegate.tableview reloaddata]

and these -(void) reloadtableviewdata implemented viewcontroller

the sec solution failed

unfortunately , sec solution failed "unrecognized selector sent instance model"

my question

1) right solution reload tableview asynchronous info url fetching , how notify , allow view controller know " info ready , reload "

2) why sec solution failed ? (whats wrong delegate ?? seem error cause delegate )

here , basic code test sec solution , same error "unrecognized selector sent instance ...."

viewcontroller.h

#import <uikit/uikit.h> @class protocol_holder; @interface viewcontroller : uiviewcontroller @property (strong ,nonatomic) protocol_holder* holderobject; @end

viewcontroller.m

#import "viewcontroller.h" #import "protocol_holder.h" @interface viewcontroller () <mydelegate> @end @implementation viewcontroller -(protocol_holder*) holderobject{ if(!_holderobject){ _holderobject = [[protocol_holder alloc]init]; } homecoming _holderobject; } - (ibaction)reloadbutton:(uibutton *)sender { nslog(@"button pushed"); [self.holderobject reload_container]; } - (void)viewdidload { [super viewdidload]; self.holderobject.delegate = self; } -(void) reload_model{ // [self.tableview reloaddata] should begin; nslog(@"enemy reload reload reload reload!!"); } @end

protocol_holder.h

#import <foundation/foundation.h> protocol mydelegate <nsobject> -(void) reload_model; @end @interface protocol_holder : nsobject {id<mydelegate> delegate;} @property (weak,nonatomic) id<mydelegate> delegate; -(void) reload_container; @end

protocol_holder.m

#import "protocol_holder.h" @interface protocol_holder() <mydelegate> @end @implementation protocol_holder -(void) reload_container{ [self reload_model]; } @end

you wrong need ready on viewdidload because request downloading data take own time depending on connectivity time show activity indicator displaying message please wait downloding neccessary data.

downloading request can added in viewdidload method

also tableview should have header displaying message no records.

when download completes can reload tableview or if download fails alert user displaying appropriate message

objective-c uitableview delegates

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -