IOS博客项目搭建-21-提醒数字

发布时间:2019-06-13 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了IOS博客项目搭建-21-提醒数字脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本节将实现从新浪的接口获取到用户的未读消息数,并显示在底部的Tabbar上,通过定时器每隔几秒请求新浪的接口,然后将获得的各种消息数通过badgeValue显示出来。

封装提醒未读数的请求参数和返回参数的数据模型

在Home(首页)/Model/userUnreadCount/目录下写模型
图片描述

代码:
请求参数

// 请求参数继承自IWBaseParam
//  IWUserUnreadCountParam.h
//  ITcastWeibo
//
//  Created by kaiyi on 16-6-18.
//  Copyright (c) 2016年 itcast. All rights reserved.
//

#import "IWBaseParam.h"

@interface IWUserUnreadCountParam : IWBaseParam

/**
 *  需要查询的用户ID。
 */
@PRoPErty (nonatomic, strong) NSNumber *uid;


@end

返回参数数据模型

//  返回参数数据模型
//  IWUserUnreadCountResutl.h
//  ItcastWeibo
//
//  Created by kaiyi on 16-6-18.
//  Copyright (c) 2016年 itcast. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface IWUserUnreadCountResutl : NSObject

// 新微薄未读数
@property (nonatomic, assign) int status;

// 新粉丝数
@property (nonatomic, assign) int follower;

// cmt
@property (nonatomic, assign) int cmt;

// 新私信数
@property (nonatomic, assign) int dm;

// 新通知未读数
@property (nonatomic, assign) int notice;

// 新提及我的微博数
@property (nonatomic, assign) int mention_status;


// 新提及我的评论数
@property (nonatomic, assign) int mention_cmt;

// 未读消息的总数
-(int)messageCount;

@end

在Main(主要)/Controller/IWTabBarViewController.m目录中发送请求

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 初始化tabbar
    [self SETUPTabbar];
    
    // 初始化所有的子控制器
    [self setupAllChildViewControllers];
    
    [self checkUnreadCount];
    
    // 定时检查未读数
    [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(checkUnreadCount) userInfo:nil repeats:YES];
}


// 定时检查未读数
-(void)checkUnreadCount
{
    // 1.请求参数
    IWUserUnreadCountParam *param = [IWUserUnreadCountParam param];
    param.uid = @([IWAccountTool account].uid);
    
    // 2.发送请求
    [IWUserTool userUnreadCountWithParam:param success:^(IWUserUnreadCountResutl *result)
    {
        // 3.设置badgeValue
        // 3.1首页
        self.home.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d", result.status];
        
        self.message.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d", result.messageCount];
        
        self.me.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d", result.follower];
       
    } failure:^(NSError *error)
    {
        
    }];
    
    
}

通过下拉刷新,清除提醒数字:
Home(首页)/Controller/IWHomeViewController.m

/**
 *   刷新数据(向新浪获取更新的微博数据)
 */
- (void)loadNewData
{
    // 0.清除提醒数据
    self.tabBarItem.badgeValue = nil;
    
    // 1.封装请求参数  
    // 其他代码省略
}

动态图:
图片描述

项目代码,请看Github:微博开发项目源代码

脚本宝典总结

以上是脚本宝典为你收集整理的IOS博客项目搭建-21-提醒数字全部内容,希望文章能够帮你解决IOS博客项目搭建-21-提醒数字所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。