Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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 移动可扩展表视图时出错?_Ios_Objective C_Uitableview_Uitableviewsectionheader - Fatal编程技术网

Ios 移动可扩展表视图时出错?

Ios 移动可扩展表视图时出错?,ios,objective-c,uitableview,uitableviewsectionheader,Ios,Objective C,Uitableview,Uitableviewsectionheader,上下移动可扩展表视图时出错。 这是我的错误 *由于未捕获的异常“NSRangeException”而终止应用程序,原因:'*-[\uu\NSSingleObjectArrayI objectAtIndex:]:索引3超出边界[0..0]' arr = [[NSArray alloc]initWithObjects:@"obj1",@"obj2",@"obj3",@"obj4",nil]; arr1 = [[NSArray alloc]initWithObjects:@"Name1", @"nam

上下移动可扩展表视图时出错。 这是我的错误 *由于未捕获的异常“NSRangeException”而终止应用程序,原因:'*-[\uu\NSSingleObjectArrayI objectAtIndex:]:索引3超出边界[0..0]'

arr = [[NSArray alloc]initWithObjects:@"obj1",@"obj2",@"obj3",@"obj4",nil];
arr1 = [[NSArray alloc]initWithObjects:@"Name1", @"name2", @"name3", @"name4", @"name5", @"name6", nil];
arr2 = [[NSArray alloc]initWithObjects:@"arr2obj", nil];
arr3 = [[NSArray alloc]initWithObjects:@"arr3obj", nil];
arr4 = [[NSArray alloc]initWithObjects:@"arr4obj", nil];
这是我的密码

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:section]])
    {
        if (section == 0) {
            return arr1.count;
        } else if (section == 1) {
            return arr2.count ;
        } else if (section == 2) {
            return arr3.count;
        }else if (section == 3) {
            return arr4.count;
        }
    } else {

        return 0;
    }

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ViewControllerCell *cell; // = [tableView dequeueReusableCellWithIdentifier:@"ViewControllerCell"];


    cell= (ViewControllerCell *)[tableView dequeueReusableCellWithIdentifier:@"ViewControllerCell" forIndexPath:indexPath];

    cell.faqLbl.text = [tempArr objectAtIndex:indexPath.row];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection: (NSInteger)section
{
    ViewControllerCellHeader *headerView = [tableView dequeueReusableCellWithIdentifier:@"ViewControllerCellHeader"];

    headerView.faqLblTitle.numberOfLines = 0;
    headerView.faqLblTitle.lineBreakMode = NSLineBreakByWordWrapping;
    headerView.faqLblTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0];

    if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
    {
        headerView.faqLblTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:25.0];

    }

    if (headerView ==nil)
    {
        [tblView registerClass:[ViewControllerCellHeader class] forCellReuseIdentifier:@"ViewControllerCellHeader"];

        headerView = [tableView dequeueReusableCellWithIdentifier:@"ViewControllerCellHeader"];
    }

    headerView.faqLblTitle.text = [arr objectAtIndex:section];

    if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:section]])
    {
        headerView.faqBtnShowHide.selected = YES;
    }

    [[headerView faqBtnShowHide] setTag:section];
    headerView.faqBtnShowHide.tag = section;

    [[headerView faqBtnShowHide] addTarget:self action:@selector(btnTapShowHideSection:) forControlEvents:UIControlEventTouchUpInside];

    return headerView.contentView;
}

-(IBAction)btnTapShowHideSection:(UIButton*)sender
{
    if (!sender.selected)
    {
        [arrSelectedSectionIndex addObject:[NSNumber numberWithInteger:sender.tag]];

        sender.selected = YES;
    }else{
        sender.selected = NO;

        if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:sender.tag]])
        {
            [arrSelectedSectionIndex removeObject:[NSNumber numberWithInteger:sender.tag]];
        }
    }

    [tblView reloadSections:[NSIndexSet indexSetWithIndex:sender.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
    }

    - (IBAction)dropDownButton:(UIButton *)sender {

        if(sender.tag == 0) {
            tempArr = arr1;
        } else if (sender.tag == 1) {
            tempArr = arr2;
        } else if (sender.tag == 2) {
            tempArr = arr3;
        } else if (sender.tag == 3) {
            tempArr = arr4;
        }
}

您在未初始化
tempArr
numberofrowsinssection
的情况下调用了reload节,该节考虑了实际数据源,如arr1、arr2等,但
cellForRowAtIndexPath
取决于
tempArr
来填充单元格。显然,如果tempArr的值与返回将中断的单元格数量的实际数据源不同。

什么是-(iAction)dropDownButton:(UIButton*)sender方法的用途?它是为单元格动态分配数组…何时调用?我在cel上有下拉按钮,当我点击它时,它会叫…@ios开发者:对不起,我弄错了,请让我更新答案
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   if(indexPath.section == 0) {
        tempArr = arr1;
    } else if (indexPath.section == 1) {
        tempArr = arr2;
    } else if (indexPath.section == 2) {
        tempArr = arr3;
    } else if (indexPath.section == 3) {
        tempArr = arr4;
    }

    ViewControllerCell *cell; // = [tableView dequeueReusableCellWithIdentifier:@"ViewControllerCell"];


    cell= (ViewControllerCell *)[tableView dequeueReusableCellWithIdentifier:@"ViewControllerCell" forIndexPath:indexPath];

    cell.faqLbl.text = [tempArr objectAtIndex:indexPath.row];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    return cell;
}