views:

58

answers:

1

Let me start off by describing my situation. I have a main view that I wish to place a smaller scrollview subview in. Then later in code (in another method), I like to add some subviews (images and textviews) to that scrollview subview. And maybe even remove the image- and text-subviews later (in yet another method). So the image- and text-subviews ends up been a subview of a subview of the main view.

This is easily done, if it all happens inside the same method. But I can't seem to add a 3rd generation subview to the second subview from another method. Would expect something like:

[self.view.scrollviewSubview addSubview:anotherSubview];

How to target the scrollview-subview placed as subview in main view. Hope my question makes sense, it's really hard to describe in text.

+1  A: 

I'm not sure to have understood ^^

But if your problem is to access a subview you don't have a pointer to, maybe you could set a tag to your subview

[ view setTag:9000 ];

Then later in your code you could search for this view with :

[ view viewWithTag:9000 ]

Don't forget that with viewWithTag you will get an UIView class. So if you need to get a specific class, you should cast it like

(MyViewSubclassed*)[ view viewWithTag:9000 ]

Good Luck !

Vinzius
It's sure not the prettiest way, but it works well. Thanks. Btw, the thing you say about 'access a subview you don't have a pointer to'. How do I point a pointer to it? That's a bit better solution.
John Kofod
It depends on your class diagram ^^ Could you do a schema of your classes and maybe we could help you to do a better thing ;-)
Vinzius
Can I get Xcode to print out a schematic of my current project?
John Kofod
It's a small project atm. The appDelegate of course, a mainViewController where everything is happening, and a FlipsideViewController returns an edited string to mainViewController to get displayed. Simple...
John Kofod
Maybe you could declare your UISCrolLView as a class var. In the .h of the file where your need to add the subview to the uiscrollview, declare UIScrollview *myCrollView; When you create it, use "myCrollView", and then later you will have a pointer to myCrollView. Maybe if you give us some code it could be easier ^^
Vinzius