Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.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 UITableView将不显示_Ios_Objective C_Uitableview - Fatal编程技术网

Ios UITableView将不显示

Ios UITableView将不显示,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我的应用程序中有一个非常奇怪的情况,我无法解释或定位错误。 我有一个UIViewController,里面有一个tableView。 在表视图中,我有3个原型单元,还有2个部分,按如下方式划分: 第一部分:第0行单元格ID:顶丝CrollersCell 第二部分:第0行单元格ID:addCommentsCell :第1行+单元格ID:commentCell 协议中所需的方法如下所示 - (NSInteger)numberOfSectionsInTableView:(UITableView *)t

我的应用程序中有一个非常奇怪的情况,我无法解释或定位错误。 我有一个UIViewController,里面有一个tableView。 在表视图中,我有3个原型单元,还有2个部分,按如下方式划分:

第一部分:第0行单元格ID:顶丝CrollersCell 第二部分:第0行单元格ID:addCommentsCell :第1行+单元格ID:commentCell

协议中所需的方法如下所示

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger rowNum;
    if(section == 0){
        rowNum = 1;
    }else{
        rowNum = 1; // here is the problem. If i change the number of row to above 1
    }
    return rowNum;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier;
    if(indexPath.section == 0){
        cellIdentifier = episodeScrollersCell;
    }else if (indexPath.section == 1 && indexPath.row == 0){
        cellIdentifier = addCommentsCell;
    }else{
        cellIdentifier = commentCell;
    }
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    return cell;
}
现在问题出现了,当我想在第二节中有2行或以上,即在一节中有2个原型单元时,视图控制器将不会显示。我已经记录了cellforrowatinexpath:method,以查看单元格是否被加载,它们是否被加载

有什么建议吗?
谢谢,

您所做的似乎是尝试将一个可重复使用的单元出列,但有可能以前没有创建过单元。但是,如果没有创建/分配单元格,则出列将返回nil值。这会告诉程序,对于给定的indexPath,没有要显示的单元格

因此,如果您从dequeue函数中获得一个nil值,那么您的表将尝试使用给定的单元格标识符创建一个新的单元格。因此,我建议您采取以下措施:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier;
    if(indexPath.section == 0){
        cellIdentifier = episodeScrollersCell;
    }else if (indexPath.section == 1 && indexPath.row == 0){
        cellIdentifier = addCommentsCell;
    }else{
        cellIdentifier = commentCell;
    }
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if(!cell){
        if(indexPath.section == 0){
            //Initialise a new cell here, through a NIB or code
            //For eg. cell = [[UITableViewCell alloc] initWithStyle: ...];
        }
        //Do the specific initialisation for each type of cell you need here
    }
    return cell;
}
这样,当dequeue函数返回一个NIL值时,您的程序会自动创建一个新的单元格以适应该位置


希望这有帮助。

请详细说明viewcontroller不显示的内容。。当UITableView未显示时会发生什么,请在numberOfRowsInSection中设置断点。如果未命中,则100次中有99次您忘记连接表视图的数据源和委托。委托和数据源已连接。我的意思是,当我切换到包含表视图的视图控制器时,似乎segue不工作。当前视图控制器(我要从中分离的视图控制器)将保持可见,并在之后记录单元格对象,确保它不是零。