Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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 如何使subtableview调用cellforrowatinexpath函数_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 如何使subtableview调用cellforrowatinexpath函数

Ios 如何使subtableview调用cellforrowatinexpath函数,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我在主视图中添加了一个子表视图,子视图每2秒刷新一次数据,但子视图控制器中的CellForRowatineXpath函数不会自动调用。仅当我在主UI中手动移动表视图时才会调用它。有什么想法吗 创建子表视图的代码如下所示 _tableView = [[UITableView alloc]init]; _mvc = [[meterViewController alloc]initWithMeter:ipAddr protocol:protocol id: meterId]; _tableView.d

我在主视图中添加了一个子表视图,子视图每2秒刷新一次数据,但子视图控制器中的CellForRowatineXpath函数不会自动调用。仅当我在主UI中手动移动表视图时才会调用它。有什么想法吗

创建子表视图的代码如下所示

_tableView = [[UITableView alloc]init];
_mvc = [[meterViewController alloc]initWithMeter:ipAddr protocol:protocol id: meterId];
_tableView.dataSource = _mvc.self;

_tableView.frame = self.view.bounds;
[self.view addSubview:_tableView];

PS:subtableview控制器中tableview的numberOfSectionsInTableView每2秒调用一次,但cellForRowAtIndexPath仅在启动或我在主屏幕上拖动tableview使其重新绘制时调用

以下提示可能有助于重新加载子表视图:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if(tableView == superTableView){
        [subTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.1];
        return //superTableView.sectonCount
    }
    else if(tableView == subTableView){
        return //subTableView sectionCount

    }

    return //default Count, you can set 1.
}

听起来代理设置不正确。确保执行self.tableView.delegate=self。Self将是您的视图控制器,而不是您的子视图


您可以使用子视图,但必须在子视图自定义类中实现UITableViewDelegate和UITableViewDataSource协议。将tableview的委托和数据源指定给子视图

这很奇怪,但是可以使用reloadSection来调用cellForRowAtIndexPath

NSIndexSet*sections=[NSIndexSet indexSetWithIndex:i];

[self.tableView重新加载节:带有行动画的节:uitableview行动画无]

\u tableView.dataSource=\u mvc.self;是subTableView的数据源是_mvc吗?是的,我在_mvc中设置了一个2秒计时器,并在2秒计时器中调用reloadData,TableView中的NumberOfSections和numberOfRowsInSection每2秒调用一次,但cellForRowAtIndexPath不是,只有在启动或我拖动表格视图以显示更多单元格时才会调用它。numberOfRowsInSection返回6,而不是0。@user3192521您可以使用NSLog(@“tableView:%@”,tableView)检查是否所有的表格视图都可以打印,如果不能打印,则表明tableView数据源设置不正确