UITableView,numberOfRowsInSection 什么时候调用

2025-05-21 05:48:22
推荐回答(1个)
回答(1):

一般来说1- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;上面函数的执行次数是根据下面函数的
1- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;上面这个函数一般来说只会执行一次。
如果在 numberOfSectionsInTableView 返回了2个,那么numberOfRowsInSection就会执行两次,如果是10个同理。
如果在 numberOfSectionsInTableView 只返回了1个,或者没有实现 numberOfSectionsInTableView 这个代理方法的话,那么numberOfRowsInSection就只会执行一次,如果执行了多次,要么是调用了 reloadData 要么就是要多个tableView共用一个代理。否则想不到别的可能性了。