iphone - Dynamically added subviews in a UIScrollView not appearing -


i'm having lot of trouble dynamically adding subviews uiscrollview. scroll view works fine content created in nib since subviews displayed depend on data in application (a mixture of images, labels, radio buttons, etc.) need able create , display them dynamically.

according i've read seems pretty straightforward on various sites , in apple documentation. in view controller's viewdidload, i've added following code,

uilabel *testlabel = [[uilabel alloc] init]; [testlabel setframe:cgrectmake(50, 50, 100, 40)]; [testlabel settext:@"my test label"]; [scrollview addsubview:testlabel];  [testlabel release]; 

the label not appear in scroll view @ if add testlabel self.view, appears (but not in scrolling content obviously). tried adding code viewdidappear in case misunderstood order of events no luck.

when checked debugger, noticed address of scroll view 0x0 assume means null reason explain why not working. under assumption if connected scrollview pointer actual scroll view in ib, automatically assigned correct address. incorrect? if case, how go getting address of view?

-- update --
feedback. checked suggested , correct. didn't need set size of content had other dummy labels (for testing scrolling working) in nib. i'll remember later on :-)

interestingly, though, after checking code again , not making changes, ran again , worked!! not sure why i'll post reason if ever figure out...

when use scrollview need set content size doing:

scrollview.contentsize = cgsizemake(@width,@height); 

in case size should bigger 50,50 if wanna see label

hope helped


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -