RYC
RYC

Reputation: 1

I have a UIView inside of a UIScrollView. How do I reference the parent UIScrollView?

I've finally figured out how to stick a UIView inside of a UIScrollView, but now I have the problem of not being able to call the UIScrollView (who is the parent of the UIView) from within my UIView.

I've tried something like:

UIScrollView *scrollView = (UIScrollView *)self.superview;

But that's not working. My thought process was that the superview would be the container for the current view (UIView), but that returned a UIView so I just casted it to a UIScrollView, which I turned out to not be the right guess.

Upvotes: 0

Views: 1296

Answers (2)

Deepesh
Deepesh

Reputation: 643

You can add the scrollView to the UIView, thorough IB or code.

Through code you can add as

[self.view addSubView:scView];

Before that you need to add all the fields, labels and TextFields to the ScrollView. and set tags to the fields for the reference.

if u add textfield in scrollView ...

[scView addSubView: TextFieldsName];

Upvotes: 0

jbat100
jbat100

Reputation: 16827

When you call

[someView addSubview:someOtherView];

someView is automatically set as superview of someOtherView. In your case, if this

UIScrollView *scrollView = (UIScrollView *)[self superview];

does not work (you probably have a typo in your question as the "=" is missing), then you have a problem setting things up (If that's the case, post your setup code).

Upvotes: 3

Related Questions