Featured post
iphone - Very basic objective-c question-how do I make different views share information? -
so, basically, have 4 different views switched via tab bar @ bottom of screen. have view controller set each one, , work fine. problem have no idea how share information between different views-for example, have ibaction on 1 takes output of uisegmentedcontrol , stores selection integer (1,2,3,4). problem is, don't know how access integer first view controller (the 1 stuff information). i'm sure basic problem google-fu doesn't seem working here. thanks!
using mvc method, information should not stored in view controllers. should have separate object stores information, view controllers load it, , views display it. easiest way store information in application's delegate. then, whenever view controller needs find/change information, can use [[uiapplication sharedapplication] delegate]
delegate, , load/change information needed. load information update display in viewdidload or viewwilldisplay:, , change in action methods.
edit example:
delegateclass.h
@interface delegateclass : nsobject { //ivars float number1; } @property (assign) float number1; ... @end
delegateclass.m
#import "delegateclass.h" @implementation delegateclass @synthesize number1; ... @end
myviewcontroller.m
#import "delegateclass.h" @implementation myviewcontroller - (void)viewdidload { [super viewdidload]; delegateclass *delegate = [[uiapplication sharedapplication] delegate]; float number1 = delegate.number1; ... } - (ibaction)actionmethod:(id)sender { float number1 = sender.floatvalue;//get new value ((delegateclass*)[[uiapplication sharedapplication] delegate]).number1 = number1; } ... @end
- Get link
- X
- Other Apps
Comments
Post a Comment