Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning iOS5 Development.pdf
Скачиваний:
7
Добавлен:
09.05.2015
Размер:
15.6 Mб
Скачать

276

CHAPTER 8: Introduction to Table Views

NSString *key = [keys objectAtIndex:index]; if (key == UITableViewIndexSearch) {

[tableView setContentOffset:CGPointZero animated:NO]; return NSNotFound;

} else return index;

}

To tell it to go to the search box, we must do two things. First, we need to get rid of the content offset we added earlier, and then we must return NSNotFound. When the table view gets this response, it knows to scroll up to the top. So, now that we’ve removed the offset, it will scroll to the search bar rather than to the top section.

NOTE: In the tableView:sectionForSectionIndexTitle:atIndex: method, we used a special constant called CGPointZero, which represents the point (0, 0) in the coordinate system. It’s a handy, readable thing, but that constant requires the use of the Core Graphics framework. When you build your project, if you get a link error complaining about a reference to _CGPointZero, you’ll know that Xcode did not include that framework by default, and you’ll need to add it yourself. To add this framework, go to the project navigator and select the toplevel Sections item. Next, click the Build Phases tab at the top of the main pane. Then expand the

Link Binary With Libraries section, click the plus button, select CoreGraphics.framework from the list that appears, and click the Add button.

Now you can build and run your app. And there you have it—live searching in an iPhone table, with a magnifying glass in the index!

TIP: iOS includes even more cool search stuff. Interested? Go to the documentation browser and do a search for UISearchDisplay to read up on UISearchDisplayController and

UISearchDisplayDelegate. You’ll likely find this material much easier to understand once you’ve made your way through Chapter 9.

Putting It All on the Table

Well, how are you doing? This was a pretty hefty chapter, and you’ve learned a ton! You should have a very solid understanding of the way that flat tables work. You should know how to customize tables and table view cells, as well as how to configure table views. You also saw how to implement a search bar, which is a vital tool in any iOS application that presents large volumes of data. Make sure you understand everything we did in this chapter, because we’re going to build on it.

We’re going to continue working with table views in the next chapter. You’ll learn how to use them to present hierarchical data. You’ll see how to create content views that allow the user to edit data selected in a table view, as well as how to present checklists in tables, embed controls in table rows, and delete rows.

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]