ios 仿微信消息列表页面, 双击tabBar, 自动滑动至下一条未读消息的位置
- (BOOL)tabBarController:(UITabBarController*)tabBarController shouldSelectViewController:(UIViewController*)viewController{
//双击那个item
if(tabBarController.selectedIndex==0) {
if([self checkIsDoubleClick:viewController]) {
//通知消息列表页面,双击了tabbar
[[NSNotificationCenter defaultCenter] postNotificationName:@"<通知key>" object:nil];
}
}
return YES;
}
//判断是否进行了双击tabbar
- (BOOL)checkIsDoubleClick:(UIViewController*)viewController
{
static UIViewController *lastViewController =nil;
static NSTimeIntervallastClickTime =0;
if(lastViewController != viewController) {
lastViewController = viewController;
lastClickTime = [NSDate timeIntervalSinceReferenceDate];
returnNO;
}
NSTimeInterval clickTime = [NSDate timeIntervalSinceReferenceDate];
if(clickTime - lastClickTime >0.5) {
lastClickTime = clickTime;
returnNO;
}
lastClickTime = clickTime;
return YES;
}
// 快捷切换未读消息
//设置当前切换cell
@property (nonatomic, strong)NSIndexPath *currentCellIndex;
@property (nonatomic, strong)NSMutableArray *conversationListDataSource;
- (void)quicklyTogglesUnreadMsg{
if (!TableView || !conversationListDataSource || conversationListDataSource.count == 0) {
return;
}
if (self.currentCellIndex.row < conversationListDataSource.count-1) {
NSIndexPath*tempIndex = [NSIndexPath indexPathForRow:0 inSection:0];
for (NSInteger i = self.currentCellIndex.row+1; i < conversationListDataSource.count; i++) {
tempIndex = [NSIndexPath indexPathForRow:i inSection:0];
conversationModel*tempLastModel =conversationListDataSource[i];
if(tempLastModel.conversation.unreadMessageCount>0&& tempLastModel.conversation.isDisturb==NO) {
self.currentCellIndex= [NSIndexPath indexPathForRow:i inSection:0];
[TableView scrollToRowAtIndexPath:self.currentCellIndex atScrollPosition:UITableViewScrollPositionTop animated:YES];
break;
}
}
conversationModel*lastModel =conversationListDataSource[tempIndex.row];
if (tempIndex.row == conversationListDataSource.count - 1 && lastModel.isDisturb == NO && lastModel.conversation.unreadMessageCount == 0) {
self.currentCellIndex = [NSIndexPath indexPathForRow:0 inSection:0];
[self quicklyTogglesUnreadMsg];
}
}
}