tailieunhanh - Phát triển ứng dụng cho iPhone và iPad - part 5
Tham khảo tài liệu 'phát triển ứng dụng cho iphone và ipad - part 5', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Building a Simple Data-Driven Application 9 Implementing Your Data Model Class In order for your class to serve data to the Tableview you ll need a method to return the requested data. So let s create an interface method called getNameAtlndex that will return the name from the model that corresponds with the index that is passed in. Bring up your header file by selecting it in the left-hand browser pane in Xcode. Below the right brace that closes the interface definition add the following line of code to declare the getNameAtlndex interface method - NSString getNameAtIndex int index You ll also need an interface method that tells users of the class how many rows you ll be returning. So add another method to the interface called getRowCount. Below the declaration for getNameAtlndex add the declaration for getRowCount - int getRowCount Your header file should look like this Available for download on import Foundation interface DataModel NSObject - NSString getNameAtIndex int index - int getRowCount end Now let s switch over to the data model implementation file and implement the new methods. You can quickly switch between a header and implementation file in Xcode by using the shortcut key combination CTRL-OPT-UP ARROW. f You will be well served to learn the keyboard shortcuts in Xcode. The small amount ir of time that you invest in learning them will more than pay off in time saved. Below the import statement in your implementation file add a local variable to hold the data list. Typically the data in your application will come from a database or some other datasource. To keep this example simple you ll use an NSArray as the datasource. Add the following line to the file below the import statement NSArray myData 10 CHAPTER 1 INTRODUCING DATA-DRIVEN APPLICATIONS Now inside the implementation block you add the implementation of the getNameAtIndex method. Add the following code stub between the .
đang nạp các trang xem trước