ScrollView with storyboards

27 views
Skip to first unread message

a.

unread,
May 24, 2012, 6:39:03 AM5/24/12
to iphonesdkd...@googlegroups.com
Hi all,

I'm building an app using storyboards.

In a view, i have a UIScrollView, in wich i want to add multiple subviews (the same one X times).

Here's my code, but the problem is that only the last view is displayed:

for (int i = 0; i < 10; i++)

    {

        CGRect frame;

        frame.origin.x = 20 * i;

        frame.origin.y = 0;


        UIView *recentOffer = (UIView *)[self.view viewWithTag:10];

        

        recentOffer.frame = frame;

        UILabel *offerLocalisation = (UILabel *)[recentOffer viewWithTag:110];

        

        offerLocalisation.text = [NSString stringWithFormat:@"View %i",i];

        

        [scrollNewOffers addSubview:recentOffer];

    }


The UIView recentOffer is set in my storyboard view, in the scrollview, with the Tag 10

Could someone help me with this code ?

Thanks a lot!

Jesse Tayler

unread,
May 24, 2012, 10:50:48 AM5/24/12
to iphonesdkd...@googlegroups.com, iphonesdkd...@googlegroups.com
You wrote a loop that gets the same view over and over and moved it 20 pixels.

You likely wanted to create a new ui view each time rather than just identifying the same view and moving it over again and again....

So, yes, only the last would be displayed....



Sent from my iPad
--
You received this message because you are subscribed to the Google Groups "iPhone SDK Development" group.
To view this discussion on the web visit https://groups.google.com/d/msg/iphonesdkdevelopment/-/2N4uXG17ZIYJ.
To post to this group, send email to iphonesdkd...@googlegroups.com.
To unsubscribe from this group, send email to iphonesdkdevelop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphonesdkdevelopment?hl=en.

Arnaud Schloune

unread,
May 24, 2012, 10:55:26 AM5/24/12
to iphonesdkd...@googlegroups.com
Thanks for your reply.

So, what would be the code to create a new uiview multiple times ?

Thanks a lot!

2012/5/24 Jesse Tayler <jta...@oeinc.com>

Jesse Tayler

unread,
May 24, 2012, 11:06:10 AM5/24/12
to iphonesdkd...@googlegroups.com, iphonesdkd...@googlegroups.com
How about

UIView *recentOffer = [[UIView alloc] initWithFrame:loopFrame];

Where loopFrame is the frame you create in your loop there.

Do something similar with the ui label and you are all set.



Sent from my iPad

jaishankar

unread,
May 25, 2012, 7:59:25 AM5/25/12
to iphonesdkd...@googlegroups.com
Yup as jesse said you need to alloc init, otherwise if you need a grid view, there are si many open source available.

One such i would suggest is gmgridview available in github having lot of features. 
Sent from Gmail Mobile
Reply all
Reply to author
Forward
0 new messages