iphone - Loading a view into a UIScrollView AND getting the content inside to work -
i have tab based application working on.
i have view controller named detailsview.m, accompanying nib file called detailsview.xib. has couple of uilabels in, linked using iboutlet detailsview.m view controller. when load view controller/view using tab bar controller, works fine , uilabels populated dynamically.
now want load entire view inside uiscrollview instead can fit more content in.
so created view controller called detailsholder.m nib file called detailsholder.xib, , assigned tab bar controller.
i wrote code below load first view (detailsview) uiscrollview in second view (detailsholder). wrote in viewdidload method of detailsholder:
detailsview* detailsview = [[detailsview alloc] initwithnibname:@"detailsview" bundle: nil]; cgrect rect = detailsview.view.frame; cgsize size = rect.size; [scrollview addsubview: detailsview.view]; scrollview.contentsize = cgsizemake(320, size.height); this correctly loads sub view uiscrollview, however, labels inside detailsview no longer anything. when put nslog inside viewdidload of detailsview - never logs anything. it's if i've loaded nib ok, no longer associated view controller anymore. missing here? i'm bit of newbie in obj c/ios (but have many years actionscript/javascript knowledge.
thanks in advance,
rich
edit: contents of detailsview requested:
detailsview.h:
#import <uikit/uikit.h> #import "appmodel.h" @interface detailsview : uiviewcontroller { iboutlet uitextview* textview; iboutlet uiimageview* imageview; } @end detailsview.m
#import "detailsview.h" @implementation detailsview - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)dealloc { [super dealloc]; } - (void)didreceivememorywarning { // releases view if doesn't have superview. [super didreceivememorywarning]; // release cached data, images, etc aren't in use. } #pragma mark - view lifecycle - (void)viewdidload { [super viewdidload]; // additional setup after loading view nib. } - (void)viewwillappear:(bool)animated { appmodel* model = [appmodel sharedinstance]; [model loaddata]; int selectedlocation = [model getselectedlocation]; nsarray *locations = [model getlocations]; nsarray *data = [locations objectatindex:selectedlocation]; textview.text = [data objectatindex: 0]; uiimage *theimage = [uiimage imagewithcontentsoffile:[[nsbundle mainbundle] pathforresource:[data objectatindex: 4] oftype:@"jpg"]]; imageview.image = theimage; } - (void)viewdidunload { [super viewdidunload]; // release retained subviews of main view. // e.g. self.myoutlet = nil; } - (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation { // return yes supported orientations return (interfaceorientation == uiinterfaceorientationportrait); } @end essentially doing grabbing selectedlocation (int) singleton (which model), grabbing array model, , trying insert image , text view. in nib file, have uiimageview , uitextview, have linked 2 iboutlets declared in detailsview.h
when use view controller this, many events not occur in view controller, e.g. viewwillappear, viewwilldisappear , device rotation event. best guess did initialisation in of event methods. posting code detailsview make easier find problem.
Comments
Post a Comment