ios5 - How to add Connection Outlets from separate class file (.m) Objects to ViewController's MainStoryboard -
i want maintain data encapsulation , have separated nsobject
class (.h , .m file) viewcontroller.m
.
i have objective-c working correctly class instantiated in viewcontroller
's viewdidload
, can set, , nslog
private values via nsobject
's methods.
what can't in mainstoryboard
assign connection outlets , received actions. iboutlets
(a uilabel
, uibutton
) aren't showing in connection inspector. however, have many objects in viewcontroller
's .[hm] file can setup outlet connections to. it's new file's objects can't view in storyboard tool.
what doing wrong?
// gametimer.h #import <foundation/foundation.h> @interface gametimer : nsobject { uilabel *gametimerlabel; nstimer *gametimer; unsigned int gametimerticks; } @property unsigned int gametimerticks; @property (nonatomic, retain) iboutlet uilabel *gametimerlabel; @property (nonatomic, retain) iboutlet uibutton *startbutton; // instantiate timer - (ibaction)onstartpressed:(id)sender; // update gametimerlabel, show new value user - (void)gametimershow; // selector func our timer, manages tick count our timers - (void)gametimerevent; @end // firstviewcontroller.m #import "firstviewcontroller.h" #import "gametimer.h" @interface firstviewcontroller () @end @implementation firstviewcontroller gametimer *mygameclock; - (void)viewdidload { [super viewdidload]; mygameclock = [[gametimer alloc] init]; [mygameclock setgametimerticks:33*10]; [mygameclock gametimershow]; unsigned long myticks = mygameclock.gametimerticks; nslog(@"ticks=%lu", myticks); }
i think may confusing encapsulation role of controller. since cocoa touch framework model-view-controller, controller "manager" sits between view's user interpretation , model's data , business rules. therefore must put iboutlets , ibactions in uiviewcontroller subclasses.
build timer separate class. timer considered part of model other controllers or other objects of model can instantiate needed. let controller instantiate "timer". use controller manage "timer" operations. if need display elapsed time, controller should elapsed time "timer" object , put in appropriate control. if need set length of time in "timer" controller value view's control , put in "timer".
hope helps
Comments
Post a Comment