iOS 双击tabBar滚动tableView到指定位置

程序员 2024-10-4 12:10:53 38 0 来自 中国
我们做一个雷同于微信的功能。双击tabBar(会话列表的tabBar)然后让会话列表滚动到有未读消息的那一行!
首先 是实现 tabBar 双击 ,这个可以在网上找一大堆!通讯的话 我用的是关照 NSNotificationCenter 在双击指定的 tabBar 的时间发出关照!在对应的页面继承关照!牢记 在退出的时间要 移除关照!!!!!


直接上代码:背面有图片 




-(void)scrollToUnReadEventNSNotification *)sender{
    /* 继承到双击tabBar 关照 */
    NSDictionary* info = sender.userInfo;
    /* 记录是第频频双击 */
    intclickTimes = [[infoobjectForKey"clickTimes"]intValue];
    /* 判定如果点击的次数大于 有未读消息 的数组的个数 就把惦记次数置为1 */
    if(clickTimes >self.indexArray.count) {
        clickTimes =1;
    }
    /* 遍历如今的会话列表 找到消息范例有未读的消息 */
    for(inti =0; i<self.dataProvider.dataList.count; i++) {
        TUIConversationCellData*cellData = [self.dataArrayobjectAtIndex:i];
        /*  判定如果消息有未读消息的就把这条消息的下标添加到下标数组内里 */
        if(cellData.unreadCount>0) {
            NSString* indexString = [NSStringstringWithFormat"%d",i];
            [self.indexArrayaddObject:indexString];
        }
    }
    /* 如今就是 在小于 未读数组的范围内 每点击一次就拿数组里的下标 */
    NSIntegerselectIndex = [[self.indexArrayobjectAtIndex:clickTimes -1]intValue];
    /* 滚动 */
    NSIndexPath  *indexPath = [NSIndexPathindexPathForRow:selectIndexinSection:0];
    [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
1.png
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-18 16:51, Processed in 0.102237 second(s), 35 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表