How does a Table View really work?


#1

I don’t really understand how I made this work after reading through the chapter. I guess what is confusing me is that there is no main() function so I don’t know how the program is progressing.

BNRAppDelegate instantiates a BNRItemsViewController
This BNRItemsViewController is where the random items are generated by “init” but by using debug statements, I find that “initWithStyle” is not used. However, tableView: numberOfRowsInSection IS USED. Also tableView:cellForRowAtIndexPath is ALSO USED.

I was trying to do the Bronze Challenge and wanted to append a table beneath another table. I’m not even sure if this is possible but I tried to copy all the tableView:numberofRowinSection and tableView:cellForRowAtIndexPath stuff, and rename to “tableView2:XXX” But nothing happened.

In summary:

  1. How does the computer know to skip initWithStyle but to run tableViews?

#2

main is still there but you are not supposed to modify it. Instead, you put your code in other files, the ones that you create and the ones that Xcode has created for you. (Remember you are now working with iOS Frameworks; therefore you must follow the rules and conventions.)

[quote] was trying to do the Bronze Challenge and wanted to append a table beneath another table. I’m not even sure if this is possible but I tried to copy all the tableView:numberofRowinSection and tableView:cellForRowAtIndexPath stuff, and rename to “tableView2:XXX” But nothing happened.
[/quote]
When working with multiple table views, you must have at least one data source and an optional delegate. If you want to add a new table view, you don’t copy and modify the existing table view methods, but you create a datasource and an optional delegate and connect them to the new table view. If you want to, you can use the same datasource or delegate for all your tableviews but then you must distinguish between different tableviews in the table view’s datasource and delegate methods.

[Accelerate your learning and become a competent programmer: pretty-function.org]


#3

Thank you for your response…

So, How does the program know to skip initWithStyle but to run tableViews?


#4

I strongly recommend that you read the following guides:

  • Start Developing iOS Apps Today

  • Table View Programming Guide for iOS (Go to UITableView class reference and follow the links.)