[英]insertRowsAtIndexPaths custom style
I am trying to create a collapse table like this 我正在尝试创建一个像这样的折叠表
My code : 我的代码:
- (WordListTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"wordListTableCell";
WordListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[WordListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
NSDictionary *uu = [wordList objectAtIndex:indexPath.row];
if(!addingNewCellFlag)
{
if([[[Singleton sharedInstance] currentLaguage] isEqualToString:@"en"])
{
cell.textLabel.text = [uu valueForKey:@"tiitle_en"];
}
else if([[[Singleton sharedInstance] currentLaguage] isEqualToString:@"ru"])
{
cell.textLabel.text = [uu valueForKey:@"tiitle_ru"];
}
UIImage *buttonImage;
if(indexPath.row==0)
{
buttonImage = [[UIImage imageNamed:@"rowFirst.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
}
else
{
buttonImage = [UIImage imageNamed:@"rowMiddle.png"];
}
cell.backgroundView = [[UIImageView alloc] initWithImage:buttonImage];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.isCanExpanded = TRUE;
}
else
{
if([[[Singleton sharedInstance] currentLaguage] isEqualToString:@"en"]){
cell.textLabel.text = [uu valueForKey:@"content_en"];
}
else if([[[Singleton sharedInstance] currentLaguage] isEqualToString:@"ru"])
{
cell.textLabel.text = [uu valueForKey:@"content_ru"];
}
cell.backgroundColor = [UIColor colorWithRed:253/255.0 green:252/255.0 blue:222/255.0 alpha:1];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.textAlignment = NSTextAlignmentJustified;
cell.isCanExpanded = FALSE;
}
[cell setIsExpanded:FALSE];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
WordListTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
addingNewCellFlag = TRUE;
if(cell.isCanExpanded)
{
if(![cell isExpanded]){
[cell setIsExpanded:TRUE];
NSDictionary *uu = [wordList objectAtIndex:indexPath.row];
[wordList insertObject:uu atIndex:indexPath.row+1];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row+1 inSection:0]]
withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
}
else if ([cell isExpanded])
{
[cell setIsExpanded:FALSE];
[wordList removeObjectAtIndex:indexPath.row+1];
[self.tableView beginUpdates];
NSIndexPath * nextIndexPath = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:nextIndexPath] withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
}
}
cell = nil;
}
It works, if we click on cell we create disruption cell, is the new cell has right text ( [uu valueForKey:@"content_en"]
), but have wrong backgroundColor ( cell.backgroundView = [[UIImageView alloc] initWithImage:buttonImage];
). 它起作用,如果我们单击创建中断单元格的单元格,则新单元格具有正确的文本( [uu valueForKey:@"content_en"]
),但是有错误的backgroundColor( cell.backgroundView = [[UIImageView alloc] initWithImage:buttonImage];
)。 But sometimes the backgroundColor is right ( [UIColor colorWithRed:253/255.0 green:252/255.0 blue:222/255.0 alpha:1]
). 但有时backgroundColor是正确的[UIColor colorWithRed:253/255.0 green:252/255.0 blue:222/255.0 alpha:1]
)。
Please, tell me, how does this method works. 请告诉我,这种方法是如何工作的。
I don't see your code in 我看不到您的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Maybe it's wrong when you deal with the cells of different indexpaths. 当您处理不同索引路径的单元格时,可能是错误的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.