tailieunhanh - Lập trình ứng dụng cho iPhone part 14

Monitoring events and actions Trong chương trước bạn đã học được cách để tạo ra bộ điều khiển xem cơ bản hoàn thành vai trò điều khiển của một mô hình kiến trúc MVC. Bạn đã sẵn sàng để bắt đầu chấp nhận người sử dụng, kể từ bây giờ bạn có thể gửi cho người sử dụng tắt cho đối tượng chính xác. Người dùng có thể tương tác với chương trình của bạn theo hai cách: bằng cách sử dụng các mô hình sự kiện ở mức độ thấp hoặc bằng cách sử dụng hành động dựa vào sự. | Monitoring events and actions This chapter covers The SDK s event modeling How events and actions differ Creating simple event- and action-driven apps In the previous chapter you learned how to create the basic view controllers that fulfill the controller role of an MVC architectural model. You re now ready to start accepting user input since you can now send users off to the correct object. Users can interact with your program in two ways by using the low-level event model or by using event-driven actions. In this chapter you ll learn the difference between the two types of interactions. Then we ll look at notifications a third way that your program can learn about user actions. Of these three models it s the events that provide the lowest-level detail and which ultimately underlie everything else and so we ll begin with events. An introduction to events We briefly touched on the basics of event management in chapter 10 but as we said at the time we wanted to put off a complete discussion until we could cover them in depth we re now ready to tackle that job. 240 An introduction to events 241 Part 1 of this book dealing with web design outlined how events tend to work on the iPhone. The fundamental unit of user input is the touch a user puts his finger on the screen. This could be built into a multi-touch or a gesture but the touch remains the building block on which everything else is constructed. It s thus the basic unit that we re going to be examining in this chapter. The responder chain When a touch occurs in an SDK program you have to worry about something you didn t have to think about on the web who responds to the event. That s because SDK programs are built of tens perhaps hundreds of different objects. Almost all of these objects are subclasses of the UIResponder class which means they contain all the functionality required to respond to an event. So who gets to respond The answer is embedded in the concept of the responder chain. This is a .