gpt4 book ai didi

ios - 如何在具有UITableview行的UICollectionViewCell中显示Json Array数据?

转载 作者:行者123 更新时间:2023-12-01 18:07:39 26 4
gpt4 key购买 nike

我有一个json数组-

  (
(
(
xyz,
abc,
efg,
hij
),
(
suv,
xyz,
pqr,
lmn
),
(
kmn,
mno,
"uvw",
"xt"
),
(
"pqr",
lm
)
),

)

问题是我想在上面的json数据数组中给定的“TableView”行中显示每个名称。那就是为什么我在“UICollectionViewCell”中使用Tableview作为
enter image description here

我正在这样做

在“GroupCollectionViewCell”内部-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *CellIdentifier = @"TableCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

cell.textLabel.text =[_groupData objectAtIndex:indexPath.row];

return cell;
}

在“ViewController.h”内部-
 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView   cellForItemAtIndexPath:(NSIndexPath *)indexPath 

{

GroupCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[GroupCollectionViewCell alloc] init];
// [cell.groupData addObjectsFromArray:_grouplist];
//:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[cell loadTableData:_grouplist];
cell.delegate=self;
return cell;
}

最佳答案

尝试将数组分组为单个数组并将其传递的想法。

这是我尝试过的示例,输出如下所示。

for (int i=0; i<responceArray.count; i++) 
{
mainARRAY=[responceArray objectAtIndex:i];
for (int j=0; j<mainARRAY.count; j++)
{
arrayForEachTable=[mainARRAY objectAtIndex:j];
[_groupData addObject:arrayForEachTable];
}
}

Output

要打印_groupData,您需要在代码中进行一些更改

在GroupCollectionViewCell.h中

@property(strong,nonatomic) NSMutableArray *cellData;

在GroupCollectionViewCell.m中


- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {

self.cellData = [[NSMutableArray alloc] init];
}
return self;
}
-(void) awakeFromNib{
self.cellData = [[NSMutableArray alloc] init];
}

在GroupCollectionViewCell.m中,您拥有tableView DataSoure方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"TableCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = [self.cellData objectAtIndex:indexPath.row];

return cell;
}

在“ViewController.h”内部
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
GroupCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

cell.cellData = [_groupData objectAtIndex:indexPath.row];//here you pass the content for printing the array
cell.delegate = self;
return cell;
}

关于ios - 如何在具有UITableview行的UICollectionViewCell中显示Json Array数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37989119/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com