views:

61

answers:

1

i may be making more out of this because of the late hour. i am confused. i have multiple views i call from a viewcontroller class. typically they are called with a uibutton object. say i have two views. main and child view. here is how i would call the child while the main view is visible.

[self presentModalViewController:childViewController animated:YES];

now because i want to use touch events to call the child view i believe i am forced to initiate the events from with the main view's class.

so how do i call the child view from within the main view class as i would when i am in the view controller class.

thanks for any help!!

+1  A: 

If I understand you correctly, you're wondering if you need to handle touches in the main view itself, rather than in the main view controller. If that is correct, the answer is no, you don't have to.

The way events work in Cocoa is that they propagate up through a chain of objects called the responder chain. The last/lowest object in the chain is given a chance to respond to the events first. In this case, that object is your "main view". If the object can not respond to the event, the event goes to the next object in the chain, what's called the object's next responder. This progresses up the chain until an object responds to the event.

The reason you don't have to worry about this is that a UIView's next responder is its view controller. This means that if you don't handle the event in your view, it propagates up to the view's controller (and, if you don't handle it there either, it continues up the responder chain). So, if you implement the -touchesBegan:withEvent:, -touchesMoved:withEvent, and the other event-based methods in your view controller and not in your view, you'll be fine.

For further reading on event handling in Cocoa, see this section of the iPhone Application Programming Guide.

jtbandes
wow..i still have alot to learn. objective c is becoming familiar but definitely not at the pace i was able to grasp vb.net. answers like yours really help me understand the big picture which is important. i will review and let you know. thanks!
Abbacore
work like a charm! thanks again for the link and your reply...
Abbacore