Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/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
NSMutableArray在UITableView中排序和显示_Uitableview_Sorting_Nsmutablearray_Uniqueidentifier_Uitableviewsectionheader - Fatal编程技术网

NSMutableArray在UITableView中排序和显示

NSMutableArray在UITableView中排序和显示,uitableview,sorting,nsmutablearray,uniqueidentifier,uitableviewsectionheader,Uitableview,Sorting,Nsmutablearray,Uniqueidentifier,Uitableviewsectionheader,我需要从下面的数据中显示一个分组的tableview。我需要根据帐户类型对以下数组进行分类 例如:我需要显示表的节标题Savings并列出所有的储蓄类型账户,然后同样地得到唯一的账户类型,并将其作为节标题和表行中的账号。我可以使用NSSet获取节标题,但是如何获取行计数并在UITableView中显示它 <__NSArrayM 0x7f8ef1e8b790>( { "account_no" = 123; "account_type" = Savings; }, { "account_

我需要从下面的数据中显示一个分组的tableview。我需要根据帐户类型对以下数组进行分类

例如:我需要显示表的节标题Savings并列出所有的储蓄类型账户,然后同样地得到唯一的账户类型,并将其作为节标题和表行中的账号。我可以使用NSSet获取节标题,但是如何获取行计数并在UITableView中显示它

<__NSArrayM 0x7f8ef1e8b790>(
{
"account_no" = 123;
"account_type" = Savings;
},
{
"account_no" = 123456;
"account_type" = Savings;
},
{
"account_no" = 00000316;
"account_type" = "DPN STAFF NON EMI";
},
{
"account_no" = 1000000552;
"account_type" = "DPN STAFF EMI LOANS";
})
我需要在UITableView中显示上述数据,如

第0节节约

第1-123行

第2行-123456

第1节-->DPN员工非电磁干扰

第1行-00000316

谢谢

AKC

请尝试以下代码:


你也可以使用NSDictionary。下面的代码工作得很好

if([arrySelectedDetails count] >0){

        grouped = [[NSMutableDictionary alloc] initWithCapacity:arrySelectedAcctDetails.count];
        for (NSDictionary *dict in arrySelectedDetails) {
            id key = [dict valueForKey:@"type"];

            NSMutableArray *tmp = [grouped objectForKey:key];
            if (tmp == nil) {
                tmp = [[NSMutableArray alloc] init];
                [grouped setObject:tmp forKey:key];

            }
            [tmp addObject:dict];

        }


        typeArray= [[NSMutableArray alloc]init];

        for(NSDictionary *groupId in arrySelectedDetails){

            if(!([typeArray count]>0)){
                [typeArray addObject:[groupId valueForKey:@"type"]];

            }
            else if (![typeArray containsObject:[groupId valueForKey:@"type"]]) {
                [typeArray addObject:[groupId valueForKey:@"type"]];

            }

        }
    }
然后,对于UITableView委托:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [typeArray count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [grouped[[typeArray objectAtIndex:section]] count]
}

嗨,艾宾,谢谢你的密码。它工作得很好。但如何在UITableView中将其显示为节标题和行?
if([arrySelectedDetails count] >0){

        grouped = [[NSMutableDictionary alloc] initWithCapacity:arrySelectedAcctDetails.count];
        for (NSDictionary *dict in arrySelectedDetails) {
            id key = [dict valueForKey:@"type"];

            NSMutableArray *tmp = [grouped objectForKey:key];
            if (tmp == nil) {
                tmp = [[NSMutableArray alloc] init];
                [grouped setObject:tmp forKey:key];

            }
            [tmp addObject:dict];

        }


        typeArray= [[NSMutableArray alloc]init];

        for(NSDictionary *groupId in arrySelectedDetails){

            if(!([typeArray count]>0)){
                [typeArray addObject:[groupId valueForKey:@"type"]];

            }
            else if (![typeArray containsObject:[groupId valueForKey:@"type"]]) {
                [typeArray addObject:[groupId valueForKey:@"type"]];

            }

        }
    }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [typeArray count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [grouped[[typeArray objectAtIndex:section]] count]
}