HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UITableView控件上的不同行为大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有这样的控制,我真的很感激: github link的问题是,现在我有一种情况,当我需要打开一行,所有以前的应该关闭,我只能有一个打开的行当时.

由于我对xcode不是很有经验,我需要一些关于我应该在哪里开始的信息,以及必要的步骤来使代码按照我现在的方式工作.

我设法做了一些测试,但不是一个可行的解决方案,这里是我现在所拥有的:

- (void)tableView:(UITableView *)tableView didSELEctRowATindexPath:(NSIndexPath *)indexPath
{
    [tableView deSELEctRowATindexPath:indexPath animated:YES];

    NSInteger row = indexPath.row;

    if (indexPath.section == 0) {

        NSLog(@"indexPath1 = %i",SELEctedRow);

        NSDictionary *d = [self.firstForTable objectATindex:indexPath.row];

        if([d valueForKey:@"Objects"]) {
            NSArray *ar = [d valueForKey:@"Objects"];

            NSUInteger count = indexPath.row +1;
            NSMutableArray *arCells = [NSMutableArray array];

            for(NSDictionary *dInner in ar ) {
                [arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
                [self.firstForTable insertObject:dInner aTindex:count++];
            }

            [tableView insertRowsATindexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft];
        }
        else {
            NSLog(@"Leave Element:::%@ %@|",[d valueForKey:@"name"],[d valueForKey:@"book"]);
        }

        if (SELEctedRow == row) {
            NSLog(@"SELEctedRow2 = %i",SELEctedRow);

            NSDictionary *d=[self.firstForTable objectATindex:SELEctedRow];

            if([d valueForKey:@"Objects"]) {
                NSArray *ar = [d valueForKey:@"Objects"];

                [self miniMizeFirstsRows:ar];
            }

            SELEctedRow = -1;
            return;
        }

        if (SELEctedRow >= 0) {
            NSLog(@"SELEctedRow3 = %i",SELEctedRow);

            NSDictionary *d=[self.firstForTable objectATindex:SELEctedRow];

            if([d valueForKey:@"Objects"]) {
                NSArray *ar = [d valueForKey:@"Objects"];

                [self miniMizeFirstsRows:ar];
            }

            SELEctedRow = row;
        }

        SELEctedRow = row;
        [tableView beginupdates]; [tableView endupdates];
    }


    if (indexPath.section == 1) {
        NSDictionary *d = [self.secondForTable objectATindex:indexPath.row];

        if([d valueForKey:@"Objects"]) {
            NSArray *ar = [d valueForKey:@"Objects"];
            BOOL isAlreadyInserted=NO;

            for (NSDictionary *dInner in ar) {
                NSInteger index = [self.secondForTable indexOfObjectIdenticalTo:dInner];

                isAlreadyInserted = (index > 0 && index != NSIntegerMaX);
                if (isAlreadyInserted) break;
            }

            if (isAlreadyInserted) {
                [self miniMizeSecondsRows:ar];
            }
            else {
                NSUInteger count = indexPath.row+1;
                NSMutableArray *arCells = [NSMutableArray array];

                for (NSDictionary *dInner in ar ) {
                    [arCells addObject:[NSIndexPath indexPathForRow:count inSection:1]];
                    [self.secondForTable insertObject:dInner aTindex:count++];
                }

                [tableView insertRowsATindexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft];
            }
        }
        else {
            NSLog(@"Leave Element:::%@ %@|",[d valueForKey:@"book"]);
        }
    }
}

提前致谢.

解决方法

更新: Expandable Rows JSON是您的项目,自动崩溃为所有行工作.

另外检查Expandable Rows,我打了这个项目来帮助诺瓦拉,并改进它.现在正在为所有部分工作,除了嵌套的行.

第一步

跟踪每个部分打开的行.当然这可以通过使用多个部分的打开的NSArray来完成.

@interface RootViewController : UITableViewController {
    NSInteger tabOpened_1;
    NSInteger tabOpened_2;
}

第二步

接下来使用“-1”值初始化那些,没有打开的选项卡.

- (void)viewDidLoad
{
    ........

    [self.firstForTable addObjectsFromArray:self.firstArray];
    tabOpened_1 = -1;
    [self.secondForTable addObjectsFromArray:self.secondarray];
    tabOpened_2 = -1;
}

第三步

更改didSELEctRowATindexPath

- (void)tableView:(UITableView *)tableView didSELEctRowATindexPath:(NSIndexPath *)indexPath
{
    [tableView deSELEctRowATindexPath:indexPath animated:YES];

        if (indexPath.section==0) {
            NSDictionary *d=[self.firstForTable objectATindex:indexPath.row];
            if([d valueForKey:@"produtos"]) {
                if (tabOpened_1 == -1) {
                    NSLog(@"No tab opened in first section");
                    tabOpened_1 = indexPath.row;
                } else if(tabOpened_1 != indexPath.row && tabOpened_1 > indexPath.row){
                    NSDictionary *d_ = [self.firstForTable objectATindex:tabOpened_1];
                    NSArray *ar_ = [d_ valueForKey:@"produtos"];
                    [self miniMizeFirstsRows:ar_];
                    tabOpened_1 = indexPath.row;
                }

                NSArray *ar=[d valueForKey:@"produtos"];
                BOOL isAlreadyInserted=NO;

                for(NSDictionary *dInner in ar ){
                    NSInteger index=[self.firstForTable indexOfObjectIdenticalTo:dInner];
                    isAlreadyInserted=(index>0 && index!=NSIntegerMaX);
                    if(isAlreadyInserted) break;
                }

                if(isAlreadyInserted) {
                    [self miniMizeFirstsRows:ar];
                } else {
                    NSUInteger count=indexPath.row+1;
                    NSMutableArray *arCells=[NSMutableArray array];
                    for(NSDictionary *dInner in ar ) {
                        [arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
                        [self.firstForTable insertObject:dInner aTindex:count++];
                    }
                    [tableView insertRowsATindexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft];
                }

                if (tabOpened_1 == -1) {
                    NSLog(@"No tab opened in first section");
                    tabOpened_1 = indexPath.row;
                } else if(tabOpened_1 != indexPath.row && tabOpened_1 < indexPath.row){
                    NSDictionary *d_ = [self.firstForTable objectATindex:tabOpened_1];
                    NSArray *ar_ = [d_ valueForKey:@"produtos"];
                    [self miniMizeFirstsRows:ar_];
                    tabOpened_1 = indexPath.row - [ar_ count];
                    tabOpened_1 = (tabOpened_1 < 0) ? indexPath.row : tabOpened_1;
                }
            } else {
               NSLog(@"Leave Element:::%@ %@|",[d valueForKey:@"nome"],[d valueForKey:@"numeroConta"]);
            }
            for (int i=0; i < [[self.rowsPerSection objectATindex:indexPath.section] IntegerValue]; i++) {
                NSDictionary *d_ = [self.secondForTable objectATindex:i];
                NSArray *ar_ = [d_ valueForKey:@"produtos"];
                [self miniMizeSecondsRows:ar_];
            }
        }

        if (indexPath.section==1) {
            if (tabOpened_2 == -1) {
                NSLog(@"No tab opened in second section");
                tabOpened_2 = indexPath.row;
            } else if(tabOpened_2 != indexPath.row && tabOpened_2 > indexPath.row){
                NSDictionary *d_ = [self.secondForTable objectATindex:tabOpened_2];
                NSArray *ar_ = [d_ valueForKey:@"produtos"];
                [self miniMizeSecondsRows:ar_];
                tabOpened_2 = indexPath.row;
            }

            NSDictionary *d=[self.secondForTable objectATindex:indexPath.row];
            if([d valueForKey:@"produtos"]) {
                NSArray *ar=[d valueForKey:@"produtos"];

                BOOL isAlreadyInserted=NO;

                for(NSDictionary *dInner in ar ){
                    NSInteger index=[self.secondForTable indexOfObjectIdenticalTo:dInner];
                    isAlreadyInserted=(index>0 && index!=NSIntegerMaX);
                    if(isAlreadyInserted) break;
                }

                if(isAlreadyInserted) {
                    [self miniMizeSecondsRows:ar];
                } else {

                    NSUInteger count=indexPath.row+1;
                    NSMutableArray *arCells=[NSMutableArray array];
                    for(NSDictionary *dInner in ar ) {
                        [arCells addObject:[NSIndexPath indexPathForRow:count inSection:1]];
                        [self.secondForTable insertObject:dInner aTindex:count++];
                    }
                    [tableView insertRowsATindexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft];
                }

                if (tabOpened_2 == -1) {
                    NSLog(@"No tab opened in second section");
                    tabOpened_2 = indexPath.row;
                } else if(tabOpened_2 != indexPath.row && tabOpened_2 < indexPath.row){
                    NSDictionary *d_ = [self.secondForTable objectATindex:tabOpened_2];
                    NSArray *ar_ = [d_ valueForKey:@"produtos"];
                    [self miniMizeSecondsRows:ar_];
                    tabOpened_2 = indexPath.row - [ar_ count];
                    tabOpened_2 = (tabOpened_2 < 0) ? indexPath.row : tabOpened_2;
                }
            } else {
                //NSLog(@"Leave Element:::%@ %@|",[d valueForKey:@"book"]);
            }

            for (int i=0; i < [[self.rowsPerSection objectATindex:indexPath.section] IntegerValue]; i++) {
                NSDictionary *d_ = [self.firstForTable objectATindex:i];
                NSArray *ar_ = [d_ valueForKey:@"produtos"];
                [self miniMizeFirstsRows:ar_];
            }
        }
}

大佬总结

以上是大佬教程为你收集整理的ios – UITableView控件上的不同行为全部内容,希望文章能够帮你解决ios – UITableView控件上的不同行为所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。