class - Objective-C Shared variables between classes -


basically i've implemented connection method parses json url, via sendasynchronousrequest. everything's working nicely. @ end of sendasynchronousrequest function, need reload tableview (since data arrived , need show it).

currently i'm doing sending tableview parameter function of class connection

@implementation whoswhereconnection  - (void)setupconnection:(uitableview *)tableview {  ...  [tableview reloaddata]; ... } 

and calling function with

[connection setupconnection:self.tableview]; 

it's working intended, feel ins't elegant way of doing it. recommend?

wish accept answers, thank helping :)

better have delegate method / block called on completion, or post notification (if multiple instances interested in event). allow break dependency have making actions performed result of completion event anonymous whoswhereconnection class. simplest change replace table view parameter block.


using delegate requires code. other answers show code other options.

for delegation, want:

  1. a protocol define method(s) called
  2. a property hold delegate object reference
  3. usage of delegate
  4. implementation of delegate method(s)

1, 2 & 3 on whoswhereconnectiondelegate class. 4 on table view controller.

1.

@protocol whoswhereconnectiondelegate < nsobject >  - (void)connection:(whoswhereconnectiondelegate *)connection didcompletewithstatus:(bool)status;  @end 

2.

@property (weak, nonatomic) id < whoswhereconnectiondelegate > delegate; 

3.

you don't show setupconnection does, delegate call should made once connection complete.

- (void)setupconnection {      bool status = no;     ...      // stuff here process things , determine status     ...     [self.delegate connection:self didcompletewithstatus:status];     ... } 

4.

the table view controller sets delegate of connection before connection starts.

 - (void)connection:(whoswhereconnectiondelegate *)connection didcompletewithstatus:(bool)status {     [self.tableview reloaddata]; } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -