Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么NumberOfSectionsTableView在没有做任何事情的情况下被调用了这么多次(4次)_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 为什么NumberOfSectionsTableView在没有做任何事情的情况下被调用了这么多次(4次)

Ios 为什么NumberOfSectionsTableView在没有做任何事情的情况下被调用了这么多次(4次),ios,objective-c,uitableview,Ios,Objective C,Uitableview,我将UIViewController和UITableView作为子视图,当我在-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView中设置断点时,我希望它只调用一个,但结果它被调用了4次 下面是相关代码的一部分 #define FunctionLog NSLog(@"<%@:%@:%d>", NSStringFromClass([self class]), NSStringFromSelector(_cmd),

我将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;
}
#定义函数log NSLog(@“),NSStringFromClass([self class]),NSStringFromSelector(_cmd),uuu LINE_uu);
#pragma标记-UITableViewDataSource
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
函数日志
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
函数日志
返回5;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
函数日志
静态NSString*cellIdentifier=@“basicCell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
cell.textLabel.text=[NSString stringWithFormat:@“单元格编号%ld”,(长)indexPath.row];
返回单元;
}
这是日志

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>
2015-07-0316:54:24.528[20394:1570424]
2015-07-03 16:54:25.527 [20394:1570424] 
2015-07-03 16:54:25.527 [20394:1570424] 
2015-07-03 16:54:40.467 [20394:1570424] 
2015-07-03 16:54:40.469 [20394:1570424] 
2015-07-03 16:54:42.724 [20394:1570424] 
2015-07-03 16:54:42.724 [20394:1570424] 
2015-07-03 16:54:43.994 [20394:1570424] 
2015-07-03 16:54:43.994 [20394:1570424] 
2015-07-03 16:54:43.998 [20394:1570424] 
2015-07-03 16:54:43.999 [20394:1570424] 
2015-07-03 16:54:44.000 [20394:1570424] 
2015-07-03 16:54:44.000 [20394:1570424] 

Cocoa Touch magic:D