置顶聊天的功能
本文小白,仅供参考。
使用协议来处理。
-(void)didTapReturnCell:(SLYPrivateChatView *)cell
// 进入到视图的里面
[self.delegate didTapPrivateChatForSecret:cell.secret withAliasName:cell.senderAliasId];
[self.delegate didTapReturnCell:self];
-(void)didTapReturnCell:(SLYPrivateChatView *)cell
{
DDLogInfo(@"didTapReturnCell Tag %i section %i",cell.tag,[[NSIndexPath alloc]initWithIndex:cell.tag-500].section);
// 改变数据的位置
if(cell.privateChat[@"isSticky"])
{
if(cell.tag-500!=0)
{
NSMutableArray* array = [[NSMutableArray alloc]initWithArray:[[Whispr soul]privateChats]];
[array exchangeObjectAtIndex:cell.tag-500 withObjectAtIndex:0];
[[Whispr soul] setPrivateChats:array];
}
}
else
{
// 取消置顶 按照时间来 插入排序
int pos = 0;
for(id each in [[Whispr soul]privateChats])
{
if(each[@"UpdateTime"]<cell.privateChat[@"UpdateTime"])
break;
else
pos++;
}
NSMutableArray* array = [[NSMutableArray alloc]initWithArray:[[Whispr soul]privateChats]];
if(pos>=[array count])
{
pos = [array count]-1;
}
if(pos!=cell.tag-500)
{
id temp = [array objectAtIndex:cell.tag-500];
[array removeObjectAtIndex:cell.tag-500];
[array insertObject:temp atIndex:pos];
[[Whispr soul] setPrivateChats:array];
}
}
[collectionView_ reloadData];
}