摘自文档:

Important: It is possible that your datasource methods for populating the table view may be called before awakeFromNib is called if the datasource is specified in Interface Builder. You should defend against this by having the datasource’s numberOfRowsInTableView: method return 0 for the number of rows when the datasource has not yet been configured. In awakeFromNib, when the datasource is initialized you should always call reloadData on the table view.

翻译如下:

dataSource已经在InterfaceBuilder里设置好的情况下,TableView在调用awakeFromNib方法之前就有可能会尝试调用dataSource的方法,而这个时候dataSource还没有就绪,应该在numberOfRowsInTableView里返回0,在awakefromNib方法里,当dataSource已经就绪之后总是应该调用tableView的reloadData。