Ios 在单元格选择时向UITableViewcell动态添加新对象
我使用UITableView在一行中显示每个团队的分数列表。我希望这样,当用户选择任何特定的单元格(团队)来查看分数时,单元格的高度会加倍,因此所选团队的分数会变得可见。我可以在选择和取消选择时调整行高,但无法动态添加标签以列出分数。请针对这种情况提出一些解决方案。如何将对象(标签)动态添加到DidSelectRowatineXpath上的uitableviewcellIos 在单元格选择时向UITableViewcell动态添加新对象,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我使用UITableView在一行中显示每个团队的分数列表。我希望这样,当用户选择任何特定的单元格(团队)来查看分数时,单元格的高度会加倍,因此所选团队的分数会变得可见。我可以在选择和取消选择时调整行高,但无法动态添加标签以列出分数。请针对这种情况提出一些解决方案。如何将对象(标签)动态添加到DidSelectRowatineXpath上的uitableviewcell - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInS
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_balls count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cell for row at index path");
static NSString *cellIdentifier = @"Cell";
CommentaryTableCell *tableCell = (CommentaryTableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (tableCell == nil) {
tableCell = [[CommentaryTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
// Configure the cell...
/*
if(indexPath.row % 2 == 0)
tableCell.backgroundColor = [self colorWithHexString:@"EAEAEA"];
else
tableCell.backgroundColor = [UIColor clearColor];
*/
NSString *over = [_balls objectAtIndex:indexPath.row];
NSArray *overData = [_ballsPerOver objectForKey:over];
NSString *ball1 = [overData objectAtIndex:0];
NSString *ball2 = [overData objectAtIndex:1];
NSString *ball3 = [overData objectAtIndex:2];
NSString *ball4 = [overData objectAtIndex:3];
NSString *ball5 = [overData objectAtIndex:4];
NSString *ball6 = [overData objectAtIndex:5];
tableCell.overLabel.text = over;
tableCell.ball1.image = [UIImage imageNamed:ball1];
tableCell.ball2.image = [UIImage imageNamed:ball2];
tableCell.ball3.image = [UIImage imageNamed:ball3];
tableCell.ball4.image = [UIImage imageNamed:ball4];
tableCell.ball5.image = [UIImage imageNamed:ball5];
tableCell.ball6.image = [UIImage imageNamed:ball6];
tableCell.teamLabel.text = @"IND";
tableCell.ball1Label.text = ball1;
tableCell.ball2Label.text = ball2;
tableCell.ball3Label.text = ball3;
tableCell.videoThumbnail.image = [UIImage imageNamed:@"th1.jpg"];
return tableCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
int rowHeight;
if ([indexPath row] == self.currentSelection)
{
rowHeight = self.newCellHeight;
}
else
{
rowHeight = 44.0f;
}
return rowHeight;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// do things with your cell here
static NSString *cellIdentifier = @"Cell";
CommentaryTableCell *tableCell = (CommentaryTableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
// set selection
self.currentSelection = indexPath.row;
// save height for full text label
if(!self.cellSelected)
{
NSLog(@"when selected");
self.newCellHeight = (tableCell.frame.size.height) * 6;
self.cellSelected = true;
self.cellloadedOnce = true;
tableCell.videoThumbnail.hidden = false;
}
else
{
NSLog(@"when de selected");
self.newCellHeight = 44;
self.cellSelected = false;
self.cellloadedOnce = false;
}
// animate
[tableView beginUpdates];
[tableView endUpdates];
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
// do things with your cell here
NSLog(@"when De selected at row index");
// sentinel
self.currentSelection = -1;
// animate
[tableView beginUpdates];
[tableView endUpdates];
}
我认为在同一个UITableViewCell上显示它不是一个好的解决方案。我建议使用另一个概念,使用导航推送在另一个UITableView中显示所有分数
如果确实要这样做,您可以始终显示所有UITableViewCell的分数,并在单击时调整单元格的高度 谢谢你的建议。好吧,我已经试着实现你在第一个位置给出的第二个选项…但是它没有很好地工作…所有的分数都在它关联的单元格上重叠…第二个呢?您可以通过添加当前团队的所有分数并在用户单击..时更改高度来构建单元格@djoosi…这就是我正在做的…我已经将分数标签添加到团队名称下方的单元格中,并限制了大小,以便唯一的团队名称可见。现在单击单元格…我的单元格的高度增加,但分数不可见。@djoosi..我已发布代码供您参考…我已在单元格中创建了这些标签,并制作了IBOutlets以供参考。将这些分数标签始终放在单元格中,只在
didSelect
/didSelect
方法?@JakubVano我已经尝试过这种方法。。。它不起作用。您是否正在尝试实现类似于手风琴视图的功能?@NSDumb是一种手风琴视图,行中的内容在行展开/折叠时分别显示/隐藏。如果是这种情况,请查看以下内容:@sonal第三方控件必须根据您的要求进行审查,然后需要与应用程序