Multi-Level UITableView?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
10 views
Need to do a lot uravneniy table. For example, in the beginning we only have 3 cells
cc9f19a769b613a2fcaa7337ab02c1fa.png


Tapaya on the first we will add the cell of the second level 1d09805ad46be36022dc59a7bb3b88f1.png


And on the 3rd level


I understand that this is a simple insertRowsAtIndexPaths But I have retrieved data from different arrays. I think you need to use what is the status for each case. But I can't figure out how. Maybe someone did something like that? Share your snippets ;)
by | 10 views

1 Answer

0 like 0 dislike
Did a similar.
\r
At the entrance missive (NSArray), each element has a level. Ran through the array and created vewwy with a shift to the left. Then it's all shoved in a UITableViewCell.
\r
\r
-(void) flateCommentsData:(NSArray *)_data withLevel:(NSInteger)level { NSEnumerator * dataEnum = [_data objectEnumerator]; NSDictionary * commentData; while (commentData = [dataEnum nextObject]) { SModelComment * commentModel = [[SModelComment alloc]init]; [commentModel set:@"id" withValue:[commentData objectForKey:@"id"]]; [commentModel set:@"text" withValue:[commentData objectForKey:@"text"]]; [commentModel set:@"userId" withValue:[commentData objectForKey:@"userId"]]; [commentModel setLevel:level]; CGRect cellRect = CGRectMake(commentModel.level*5, 0, 320 - commentModel.level*5, 0); UIView * cellView = [[UIView alloc] initWithFrame: cellRect]; //add avatar SModelUser * user = [SModelUserPeer loadObjectById:[commentModel get:@"userId"]]; UIImageView * avatarView = [[UIImageView alloc] initWithImage: user.smallAvatar.image ]; avatarView.frame = CGRectMake(5, 7, 35, 35); [cellView addSubview:avatarView]; //add username UILabel * usernameLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 5, cellRect.size.width - 75, 20)]; usernameLabel.font = [UIFont boldSystemFontOfSize:14.0]; usernameLabel.text = [user get:@"fullName"]; [cellView addSubview:usernameLabel]; //add text CellTextRect CGRect = CGRectMake(45, 25, cellRect.size.width - 75, 0); UILabel * cellTextLabel = [[UILabel alloc] initWithFrame:cellTextRect]; cellTextLabel.text = [commentModel get:@"text"]; cellTextLabel.font = [UIFont systemFontOfSize:12.0]; cellTextLabel.numberOfLines = 0; [cellTextLabel sizeToFit]; cellTextLabel.backgroundColor = [UIColor whiteColor]; [cellView addSubview:cellTextLabel]; CGRect textFrame = cellTextLabel.frame; textFrame.size.height = textFrame.size.height + 10 + usernameLabel.frame.size.height ; textFrame.size.height = textFrame.size.height > 50 ? textFrame.size.height : 50; cellRect.size.height = textFrame.size.height; cellView.frame = cellRect; NSMutableDictionary * item = [[NSMutableDictionary alloc] initWithCapacity:2]; [item setObject:cellView forKey:@"view"]; [item setObject:commentModel forKey:@"model"]; [commentsList addObject:item]; if ([commentData objectForKey:@"childs"]) { [self flateCommentsData:[commentData objectForKey:@"childs"] withLevel:level+1]; } } } 

\r
\rthen
\r
\r
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary * item = [commentsList objectAtIndex:indexPath.row]; UIView * cellView = [item objectForKey:@"view"]; SModelComment * commentModel = [item objectForKey:@"model"]; NSString * CellIdentifier = [NSString stringWithFormat:@"comment_cell_%d", [commentModel get:@"id"]]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } cell.accessoryType = UITableViewCellAccessoryDisclosureindicator; [cell.contentView addSubview:cellView]; return cell; } 
by

Related questions

0 like 0 dislike
1 answer
asked Apr 2, 2019 by anonymous22
0 like 0 dislike
3 answers
asked Mar 28, 2019 by nepster
0 like 0 dislike
1 answer
asked Mar 22, 2019 by VasKravchuk
0 like 0 dislike
1 answer
asked Mar 22, 2019 by Project86
110,608 questions
257,186 answers
0 comments
27,067 users