English 中文(简体)
Calling another view from within a view class
原标题:

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!!

最佳回答

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.

问题回答

暂无回答




相关问题
How do you create UIBarButtonItems with a radio interface?

I have a UIToolbar that needs three buttons in a radio style, meaning that of the three, only one button can be pushed at a time. The documentation makes reference to the possibility of setting up ...

iPhone settings bundle

I want to allow the user to enter a valid date using the iPhone’s settings application. I have experimented with many of the PreferenceSpecifiers data node types including date. I have two issues: ...

Circular #import/@class problem in ObjectiveC

I m going to use an example to properly illustrate my confusion. I can t quite wrap my head around this. In Cocoa touch, we have UIViewController and its subclass, UINavigationController. Now, UIVC ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Cocoa-Touch: issue looping MPMoviePlayerController

I have an app which has to load some data at startup, so I want to display a splash-screen animation. I m using the MPMoviePlayerController to play a m4v file. The movie has it s background set to [...

Iphone sequential animation with setAnimationDelay

I m trying to chain animation events. The application I m coding for work has a multiple choice quiz. First you pick your multiple choice answer. The quiz view fades away. Then a label ("correct" or "...

热门标签