开发者

why does "numberOrRowsInSection" get called mid-way through "viewDidLoad"?

开发者 https://www.devze.com 2023-02-18 21:49 出处:网络
BACKGROUND: Within my viewDidLoad I am loading test calendar data (via EventKit) to the iPhone.I am noting that when the table view loads the first time it does not see this data.

BACKGROUND:

  1. Within my viewDidLoad I am loading test calendar data (via EventKit) to the iPhone. I am noting that when the table view loads the first time it does not see this data.

  2. When I look at the sequence of log messages I see that it goes something like this:

Logging here:

[AppointmentListController viewDidLoad] Starting
[AppointmentListController populateTestData] Populating the test data now
[AppointmentListController tableView:numberOfRowsInSection:] Number of rows = 0
[AppointmentListController viewDidLoad] Loading the existing calendar events
[AppointmentListController viewDidLoad] Ending

QUESTION(S)

  • Why does "numberOrRowsInSection" get called mid-way through "viewDidLoad"? I ask this as this is what I am seeing (is this what should happen?).

  • If this is normal that you can't be sure viewDidLoad will complete before numberOrRowsInSection, then this would imply you need a "[self.tableView reloadData]" at the end 开发者_如何学Goof your "viewDidLoad" method to make sure it does update?


The tableView:numberOfRowsInSection: method is likely called because you configured something on your table view (maybed you've added it to its superview) and it therefor needed to know its metrics. It does not magically trigger by itself out of the blue. Either make sure to prepare your data before you configure the UI elements or call reloadData near the end, but I'd find the former to be "cleaner".


This is perfectly normal....

Call [self.tableView reloadData]

; at the end of viewdidload

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号