我有UIViewController和UITableView作为子视图,当我在- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
中设置断点时,我希望它只调用一个,但结果是4次调用。
以下是相关代码的一部分
#define FunctionLog NSLog(@"<%@:%@:%d>", NSStringFromClass([self class]), NSStringFromSelector(_cmd), __LINE__);
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
FunctionLog
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
FunctionLog
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FunctionLog
static NSString *cellIdentifier = @"basicCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:@"Cell number %ld", (long)indexPath.row];
return cell;
}
这是日志
2015-07-03 16:54:24.528 [20394:1570424] <ViewController:numberOfSectionsInTableView::34>
2015-07-03 16:54:25.527 [20394:1570424] <ViewController:tableView:numberOfRowsInSection::40>
2015-07-03 16:54:25.527 [20394:1570424] <ViewController:numberOfSectionsInTableView::34>
2015-07-03 16:54:40.467 [20394:1570424] <ViewController:tableView:numberOfRowsInSection::40>
2015-07-03 16:54:40.469 [20394:1570424] <ViewController:numberOfSectionsInTableView::34>
2015-07-03 16:54:42.724 [20394:1570424] <ViewController:tableView:numberOfRowsInSection::40>
2015-07-03 16:54:42.724 [20394:1570424] <ViewController:numberOfSectionsInTableView::34>
2015-07-03 16:54:43.994 [20394:1570424] <ViewController:tableView:numberOfRowsInSection::40>
2015-07-03 16:54:43.994 [20394:1570424] <ViewController:tableView:cellForRowAtIndexPath::46>
2015-07-03 16:54:43.998 [20394:1570424] <ViewController:tableView:cellForRowAtIndexPath::46>
2015-07-03 16:54:43.999 [20394:1570424] <ViewController:tableView:cellForRowAtIndexPath::46>
2015-07-03 16:54:44.000 [20394:1570424] <ViewController:tableView:cellForRowAtIndexPath::46>
2015-07-03 16:54:44.000 [20394:1570424] <ViewController:tableView:cellForRowAtIndexPath::46>