weibo project summary

一、第三方库
首先用到了很多第三方库,如sdwebimage、richtextlabel、regexkitlite、uiviewext、uiutils、MJRefresh

sdwebimage:异步加载网络图片,以后要经常使用。
richtextlabel:可以显示高亮的微博话题,链接等信息,原生的UILabel做不到。
regexkitlite:正则表达式,匹配出微博话题、网络链接、人名@等信息。
UIViewExt:可以快速自定义width,top,height等属性,需要导入coretext库
UIUtils:工具类,主要在微博项目中,将微博发布时间转为正常显示的格式,和将html文字转为正常的文字。
MJRefresh:上下拉刷新控件

二、Model
调用WXBaseModel类,实现基本的Model类型.
WeiboModel和UserModel继承自WXBaseModel

//字典映射,如果两者名字相同,就不需要写映射关系。
-(NSDictionary*)attributeMapDictionary
{
NSDictionary *mapAtt=@{@"created_at":@"created_at",
@"id":@"id",
@"text":@"text",
@"source":@"source",
@"favorited":@"favorited",
@"thumbnail_pic":@"thumbnail_pic",
@"bmiddle_pic":@"bmiddle_pic",
@"original_pic":@"original_pic",
@"geo":@"geo",
@"reposts_count":@"reposts_count",
@"comments_count":@"comments_count",
@"pic_urls":@"pic_urls"
};
return mapAtt;
//填充数据
-(void)setAttributes:(NSDictionary *)dataDic
{
//将字典数据根据映射关系填充到当前对象的属性
[super setAttributes:dataDic];
NSDictionary *retweetDic=[dataDic objectForKey:@"retweeted_status"];
if(retweetDic !=nil)
{
WeiboModel *retWeibo=[[WeiboModel alloc]initWithDataDic:retweetDic];
self.retweeted_status=retWeibo;//将转发的字典给对应的model
}

NSDictionary *userDic=[dataDic objectForKey:@"user"];
if(userDic!=nil)
{
UserModel *user=[[UserModel alloc]initWithDataDic:userDic];
self.user=user;
}

}
}

三、initview和layoutsubviews
initview中初始化界面元素(注:一定要初始化)
layoutsubviews填充数据.
复杂的多图微博显示创建新类PhotoView(UIView类)

四、在viewController创建对象拿取数据

    NSData *data=[result dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
    //NSArray *pics=[dic objectForKey:@"pic_ids"];
    //NSLog(@"json数据------->%@",dic);
    NSArray * statuses=[dic objectForKey:@"statuses"];
    NSMutableArray *weibos=[NSMutableArray arrayWithCapacity:1000];
    for(NSDictionary *dic in statuses)
    {
        WeiboModel *weibo=[[WeiboModel alloc]initWithDataDic:dic];
        //NSLog(@"-------%@",weibo);
        //NSLog(@"----%@pics----%@",weibo.user.screen_name,weibo.pic_urls);
        [weibos addObject:weibo];
    }
    if (weibos.count>0) {
        WeiboModel *lastWeibo=[weibos lastObject];
        self.lastWeiboId=[lastWeibo.id stringValue];
        WeiboModel *topWeibo=[weibos objectAtIndex:0];
        self.topWeiboId=[topWeibo.id stringValue];
        NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
        [defaults setObject:self.topWeiboId forKey:@"topWeiboId"];
    }
    self.data=weibos;
    self.fullWeibos=weibos;
    [self.weiboTable reloadData];

你可能感兴趣的:(weibo project summary)