2016-06-23 2 views
1

Ich habe eine json Array as-Wie werden Json-Array-Daten in UICollectionViewCell mit UITableview-Zeilen angezeigt?

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

) 

Problem ist, dass ich jeden Namen in einer „Tableview“ Zeilen in Satz angezeigt werden soll, wie oben in json Datenarray gegeben. Das ist, warum ich einer Tabellen- inside "UICollectionViewCell" als enter image description here

Ich mag dieses

Inside "GroupCollectionViewCell" tue bin mit -

- (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; 
} 

Inside "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; 
} 
+0

Sie meinen SALES sagen, MARKETING, LEGAL, COMPLIANCE in der Tabellenansicht von 1st CollectionViewCell Excel, Outlook, CMM, Proprietär in der Tabelle der nächsten Zelle? –

+0

Ihre _groupData haben korrekte Werte? – Signare

+0

Ja, nur so .. @AbhishekPM –

Antwort

4

Probieren Sie diese Idee aus, das Array in ein einzelnes Array zu gruppieren und dieses zu übergeben.

Dies ist ein Beispiel, das ich ausprobiert habe und wie unten gezeigt ausgegeben habe.

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

drucken _groupData Sie

kleine Änderungen in Ihrem Code vornehmen müssen

In GroupCollectionViewCell.h

@property(strong,nonatomic) NSMutableArray *cellData; 

In GroupCollectionViewCell.m

add

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

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

Im Inneren des GroupCollectionViewCell.m, wo Sie Ihre Tableview DataSoure Methode

- (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; 
} 

Inside "ViewController.h" haben -

- (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; 
    } 
+0

Was ist responseArray und arrayForEachTableData? –

+0

1. Array, das Sie von Ihrer JSON-Antwort handhaben, ist "responseArray" "mainArray" wird Array für jede Tabelle haben, die in "arrayForEachTableData" gespeichert wird –

+0

Können Sie mir sagen, wie Sie das Array "_groupData" Inside-Methode drucken " (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath "@AbhishekPM –

Verwandte Themen