网易代码截取

        // 多种类型单元格
#pragma mark - /************************* 类方法返回可重用 ID ***************************/
        + (NSString *)idForRow:(SXNewsModel *)NewsModel
        {
            if (NewsModel.hasHead && NewsModel.photosetID) {
                return @"TopImageCell” ;—图片 - IL
            } else if (NewsModel.hasHead){
               
return @"TopTxtCell” ;—详情  — IL
            }else if (NewsModel.imgType){
                return @"BigImageCell” ;详情 ILI
            }else if (NewsModel.imgextra){
                return @"ImagesCell” ;— -图片 LIII
            } else {
                return @"NewsCell” ;——详情  ILL
            }
        }
       
#pragma mark - /************************* 类方法返回行高 ***************************/
        + (CGFloat)heightForRow:(SXNewsModel *)NewsModel
        {
           
if (NewsModel.hasHead && NewsModel.photosetID){
               
return 245 ;
            }
else if (NewsModel.hasHead) {
               
return 245 ;
            }
else if (NewsModel.imgType) {
               
return 170 ;
            }
else if (NewsModel.imgextra){
               
return 130 ;
            }
else {
               
return 80 ;
            }
        }
     
}


#pragma mark - 运行时相关
static char MJRefreshHeaderViewKey;
static char MJRefreshFooterViewKey;

- (
void )setHeader:( MJRefreshHeaderView *)header {
    [
self willChangeValueForKey : @"MJRefreshHeaderViewKey" ];
   
objc_setAssociatedObject ( self , & MJRefreshHeaderViewKey ,
                             header,
                            
OBJC_ASSOCIATION_ASSIGN );
    [
self didChangeValueForKey : @"MJRefreshHeaderViewKey" ];
}

- (
MJRefreshHeaderView *)header {
   
return objc_getAssociatedObject ( self , & MJRefreshHeaderViewKey );
}

- (
void )setFooter:( MJRefreshFooterView *)footer {
    [
self willChangeValueForKey : @"MJRefreshFooterViewKey" ];
   
objc_setAssociatedObject ( self , & MJRefreshFooterViewKey ,
                             footer,
                            
OBJC_ASSOCIATION_ASSIGN );
    [
self didChangeValueForKey : @"MJRefreshFooterViewKey" ];
}

- (
MJRefreshFooterView *)footer {
   
return objc_getAssociatedObject ( self , & MJRefreshFooterViewKey );
}

#pragma mark - 下拉刷新
/**
 * 
添加一个下拉刷新头部控件
 *
 *  @param callback
回调
 */

- (
void )addHeaderWithCallback:( void (^)())callback
{
    [
self addHeaderWithCallback :callback dateKey : nil ];
}

- (
void )addHeaderWithCallback:( void (^)())callback dateKey:( NSString *)dateKey
{
   
// 1. 创建新的 header
   
if (! self . header ) {
       
MJRefreshHeaderView *header = [ MJRefreshHeaderView header ];
        [
self addSubview :header];
       
self . header = header;
    }
   
   
// 2. 设置 block 回调
   
self . header . beginRefreshingCallback = callback;
   
   
// 3. 设置存储刷新时间的 key
   
self . header . dateKey = dateKey;
}

/**
 * 
添加一个下拉刷新头部控件
 *
 *  @param target
目标
 *  @param action
回调方法
 */

- (
void )addHeaderWithTarget:( id )target action:( SEL )action
{
    [
self addHeaderWithTarget :target action :action dateKey : nil ];
}

- (
void )addHeaderWithTarget:( id )target action:( SEL )action dateKey:( NSString *)dateKey
{
   
// 1. 创建新的 header
   
if (! self . header ) {
       
MJRefreshHeaderView *header = [ MJRefreshHeaderView header ];
        [
self addSubview :header];
       
self . header = header;
    }
   
   
// 2. 设置目标和回调方法
   
self . header . beginRefreshingTaget = target;
   
self . header . beginRefreshingAction = action;
   
   
// 3. 设置存储刷新时间的 key
   
self . header . dateKey = dateKey;
}

/**
 * 
移除下拉刷新头部控件
 */

- (
void )removeHeader
{
    [
self . header removeFromSuperview ];
   
self . header = nil ;
}

/**
 * 
主动让下拉刷新头部控件进入刷新状态
 */

- (
void )headerBeginRefreshing
{
    [
self . header beginRefreshing ];
}

/**
 * 
让下拉刷新头部控件停止刷新状态
 */

- (
void )headerEndRefreshing
{
    [
self . header endRefreshing ];
}

/**
 * 
下拉刷新头部控件的可见性
 */

- (
void )setHeaderHidden:( BOOL )hidden
{
   
self . header . hidden = hidden;
}

- (
BOOL )isHeaderHidden
{
   
return self . header . isHidden ;
}

- (
BOOL )isHeaderRefreshing
{
   
return self . header . isRefreshing ;
}

#pragma mark - 上拉刷新
/**
 * 
添加一个上拉刷新尾部控件
 *
 *  @param callback
回调
 */

- (
void )addFooterWithCallback:( void (^)())callback
{
   
// 1. 创建新的 footer
   
if (! self . footer ) {
       
MJRefreshFooterView *footer = [ MJRefreshFooterView footer ];
        [
self addSubview :footer];
       
self . footer = footer;
    }
   
   
// 2. 设置 block 回调
   
self . footer . beginRefreshingCallback = callback;
}

/**
 * 
添加一个上拉刷新尾部控件
 *
 *  @param target
目标
 *  @param action
回调方法
 */

- (
void )addFooterWithTarget:( id )target action:( SEL )action
{
   
// 1. 创建新的 footer
   
if (! self . footer ) {
       
MJRefreshFooterView *footer = [ MJRefreshFooterView footer ];
        [
self addSubview :footer];
       
self . footer = footer;
    }
   
   
// 2. 设置目标和回调方法
   
self . footer . beginRefreshingTaget = target;
   
self . footer . beginRefreshingAction = action;
}

/**
 * 
移除上拉刷新尾部控件
 */

- (
void )removeFooter
{
    [
self . footer removeFromSuperview ];
   
self . footer = nil ;
}

/**
 * 
主动让上拉刷新尾部控件进入刷新状态
 */

- (
void )footerBeginRefreshing
{
    [
self . footer beginRefreshing ];
}

/**
 * 
让上拉刷新尾部控件停止刷新状态
 */

- (
void )footerEndRefreshing
{
    [
self . footer endRefreshing ];
}

/**
 * 
下拉刷新头部控件的可见性
 */

- (
void )setFooterHidden:( BOOL )hidden
{
   
self . footer . hidden = hidden;
}

- (
BOOL )isFooterHidden
{
   
return self . footer . isHidden ;
}

- (
BOOL )isFooterRefreshing
{
   
return self . footer . isRefreshing ;
}

/**
 * 
文字
 */

- (
void )setFooterPullToRefreshText:( NSString *)footerPullToRefreshText
{
   
self . footer . pullToRefreshText = footerPullToRefreshText;
}

- (
NSString *)footerPullToRefreshText
{
   
return self . footer . pullToRefreshText ;
}

- (
void )setFooterReleaseToRefreshText:( NSString *)footerReleaseToRefreshText
{
   
self . footer . releaseToRefreshText = footerReleaseToRefreshText;
}

- (
NSString *)footerReleaseToRefreshText
{
   
return self . footer . releaseToRefreshText ;
}

- (
void )setFooterRefreshingText:( NSString *)footerRefreshingText
{
   
self . footer . refreshingText = footerRefreshingText;
}

- (
NSString *)footerRefreshingText
{
   
return self . footer . refreshingText ;
}

- (
void )setHeaderPullToRefreshText:( NSString *)headerPullToRefreshText
{
   
self . header . pullToRefreshText = headerPullToRefreshText;
}

- (
NSString *)headerPullToRefreshText
{
   
return self . header . pullToRefreshText ;
}

- (
void )setHeaderReleaseToRefreshText:( NSString *)headerReleaseToRefreshText
{
   
self . header . releaseToRefreshText = headerReleaseToRefreshText;
}

- (
NSString *)headerReleaseToRefreshText
{
   
return self . header . releaseToRefreshText ;
}

- (
void )setHeaderRefreshingText:( NSString *)headerRefreshingText
{
   
self . header . refreshingText = headerRefreshingText;
}

- (
NSString *)headerRefreshingText
{
   
return self . header . refreshingText ;
}


// 多图 cell
   
if ( self . NewsModel . imgextra . count == 2 ) {
       
        [
self . imgOther1 sd_setImageWithURL :[ NSURL URLWithString : self . NewsModel . imgextra [ 0 ][ @"imgsrc" ]] placeholderImage :[ UIImage imageNamed : @"302" ]];
        [
self . imgOther2 sd_setImageWithURL :[ NSURL URLWithString : self . NewsModel . imgextra [ 1 ][ @"imgsrc" ]] placeholderImage :[ UIImage imageNamed : @"302" ]];
    }
   
}

#pragma mark - /************************* 类方法返回可重用 ID ***************************/
+ ( NSString *)idForRow:( SXNewsModel *)NewsModel
{
   
if (NewsModel. hasHead && NewsModel. photosetID ) {
       
return @"TopImageCell" ;
    }
else if (NewsModel. hasHead ){
       
return @"TopTxtCell" ;
    }
else if (NewsModel. imgType ){
       
return @"BigImageCell" ;
    }
else if (NewsModel. imgextra ){
       
return @"ImagesCell" ;
    }
else {
       
return @"NewsCell" ;
    }
}

#pragma mark - /************************* 类方法返回行高 ***************************/
+ ( CGFloat )heightForRow:( SXNewsModel *)NewsModel
{
   
if (NewsModel. hasHead && NewsModel. photosetID ){
       
return 245 ;
    }
else if (NewsModel. hasHead ) {
       
return 245 ;
    }
else if (NewsModel. imgType ) {
       
return 170 ;
    }
else if (NewsModel. imgextra ){
       
return 130 ;
    }
else {
       
return 80 ;
    }
}


- ( UITableViewCell *)tableView:( UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath
{
   
SXNewsModel *newsModel = self . arrayList [indexPath. row ];
   
   
NSString *ID = [ SXNewsCell idForRow :newsModel];
   
   
if ((indexPath. row % 20 == 0 )&&(indexPath. row != 0 )) {
        ID =
@"NewsCell" ;
    }
   
   
SXNewsCell * cell = [tableView dequeueReusableCellWithIdentifier :ID];
   
    cell.
NewsModel = newsModel;
   
   
return cell;
   
}




#pragma mark - /************************* tbv 代理方法 ***************************/
- ( CGFloat )tableView:( UITableView *)tableView heightForRowAtIndexPath:( NSIndexPath *)indexPath
{
   
SXNewsModel *newsModel = self . arrayList [indexPath. row ];
   
   
CGFloat rowHeight = [ SXNewsCell heightForRow :newsModel];
   
   
if ((indexPath. row % 20 == 0 )&&(indexPath. row != 0 )) {
        rowHeight =
80 ;
    }
   
   
return rowHeight;
}

- (
void )tableView:( UITableView *)tableView didSelectRowAtIndexPath:( NSIndexPath *)indexPath
{
   
// 刚选中又马上取消选中,格子不变色
    [tableView
deselectRowAtIndexPath :indexPath animated : YES ];
   
   
UIViewController *vc = [[ UIViewController alloc ] init ];
    vc.
view . backgroundColor = [ UIColor yellowColor ];
}
- ( NSArray *)arrayLists
{
   
if ( _arrayLists == nil ) {
       
_arrayLists = [ NSArray arrayWithContentsOfFile :[[ NSBundle mainBundle ] pathForResource : @"NewsURLs.plist" ofType : nil ]];
    }
   
return _arrayLists ;
}


/** 添加子控制器 */
- (
void )addController
{
   
for ( int i= 0 ; i< self . arrayLists . count ;i++){
       
SXTableViewController *vc1 = [[ UIStoryboard storyboardWithName : @"News" bundle :[ NSBundle mainBundle ]] instantiateInitialViewController ];
        vc1.
title = self . arrayLists [i][ @"title" ];
        vc1.
urlString = self . arrayLists [i][ @"urlString" ];
        [
self addChildViewController :vc1];
    }
}


+ ( instancetype )newsModelWithDict:( NSDictionary *)dict
{
   
SXNewsModel *model = [[ self alloc ] init ];
   
    [model
setValuesForKeysWithDictionary :dict];
   
   
return model;
}

@property ( nonatomic , copy ) NSString *docid;


- ( void )viewDidLoad {
    [
super viewDidLoad ];
   
self . webView . delegate = self ;
   
NSString *url = [ NSString stringWithFormat : @"http://c.m.163.com/nc/article/%@/full.html" , self . newsModel . docid ];
   
NSLog ( @"**************%@" , self . newsModel . docid );
    [[
SXHTTPManager manager ] GET :url parameters : nil success :^( AFHTTPRequestOperation *operation, id responseObject) {
       
self . detailModel = [ SXDetailModel detailWithDict :responseObject[ self . newsModel . docid ]];
        [
self showInWebView ];
    }
failure :^( AFHTTPRequestOperation *operation, NSError *error) {
       
NSLog ( @"failure %@" ,error);
    }];







//
//  ViewController.m
//  网易模板代码截取
//
//  Created by xalo on 15/10/14.
//  Copyright © 2015 蓝鸥科技 . All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (
void )viewDidLoad {
    [
super viewDidLoad];
   
// Do any additional setup after loading the view.
   
//    http://comment.api.163.com/api/json/post/list/new/hot/photoview_bbs/PHOT1ODB009654GK/0/10/10/2/2
   
//hotPosts: 评论 (   "f": " 网易英国手机网友 [Eggitch] 的原贴: ",
//            "rp": "0",
//            "u": "dCrHBy2XzjIKf8I8xEeUAaFJVm%2BrBbZd4Ltw9mV5WQA%3D",
//            "b": " 脱光了反而一点都不好看,身材不咋地 ",
//            "p": "AI3EKHJR",
//            "pi": "PHOT1ODB009654GK_AI3DHONR",
//            "ip": "82.132.230.244")

   
   
/** 提前把评论的请求也发出去 得到评论的信息 */
   
    - (
void )sendRequestWithUrl2:(NSString *)url
    {
        [[SXHTTPManager manager]GET:url parameters:
nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
            NSArray *dictarray = responseObject[
@"hotPosts" ];
           
//        NSLog(@"%ld",dictarray.count);
           
for ( int i = 0 ; i < dictarray.count; i++) {
                NSDictionary *dict = dictarray[i][
@"1" ];
                SXReplyModel *replyModel = [[SXReplyModel alloc]init];
                replyModel.name = dict[
@"n" ];
               
if (replyModel.name == nil ) {
                    replyModel.name =
@" 火星网友 " ;
                }
                replyModel.address = dict[
@"f" ];
                replyModel.say = dict[
@"b" ];
                replyModel.suppose = dict[
@"v" ];
                [
self .replyModels addObject:replyModel];
            }
           
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(
@"failure %@" ,error);
        }];
    }

   
   
    + (
void )loadLatestAdImage
    {
        NSInteger now = [[[NSDate alloc] init] timeIntervalSince1970];
        NSString *path = [NSString stringWithFormat:
@"http://g1.163.com/madr?app=7A16FBB6&platform=ios&category=startup&location=1&timestamp=%ld" ,( long )now];
       
        [[[SXNetworkTools sharedNetworkToolsWithoutBaseUrl]GET:path parameters:
nil success:^(NSURLSessionDataTask *task, NSDictionary* responseObject) {
           
            NSArray *adArray = [responseObject valueForKey:
@"ads" ];
            NSString *imgUrl = adArray[
0 ][ @"res_url" ][ 0 ];
            NSString *imgUrl2 =
nil ;
           
if (adArray.count > 1 ) {
                imgUrl2= adArray[
1 ][ @"res_url" ][ 0 ];
            }
           
           
BOOL one = [[NSUserDefaults standardUserDefaults]boolForKey: @"one" ];
           
if (imgUrl2.length > 0 ) {
               
if (one) {
                    [
self downloadImage:imgUrl];
                    [[NSUserDefaults standardUserDefaults]setBool:!one forKey:
@"one" ];
                }
else {
                    [
self downloadImage:imgUrl2];
                    [[NSUserDefaults standardUserDefaults]setBool:!one forKey:
@"one" ];
                }
            }
else {
                [
self downloadImage:imgUrl];
            }
           
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            NSLog(
@"%@" ,error);
        }] resume];
    }
   

   
   
   
   
    - (
void )sendWeatherRequest
    {
        NSString *url =
@"http://c.3g.163.com/nc/weather/5YyX5LqsfOWMl%2BS6rA%3D%3D.html" ;
        [[SXHTTPManager manager]GET:url parameters:
nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
           
            SXWeatherModel *weatherModel = [SXWeatherModel objectWithKeyValues:responseObject];
           
self .weatherModel = weatherModel;
            [
self addWeather];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(
@"failure %@" ,error);
        }];
    }
   
   
// 动画
    - (
void )rightItemClick{
       
       
if ( self .isWeatherShow) {
           
           
           
self .weatherView.hidden = YES ;
           
self .tran.hidden = YES ;
            [UIView animateWithDuration:
0.1 animations:^{
               
self .rightItem.transform = CGAffineTransformRotate( self .rightItem.transform, M_1_PI * 5 );
               
            } completion:^(
BOOL finished) {
                [
self .rightItem setImage:[UIImage imageNamed: @"top_navigation_square" ] forState:UIControlStateNormal];
            }];
        }
else {
           
            [
self .rightItem setImage:[UIImage imageNamed: @"223" ] forState:UIControlStateNormal];
           
self .weatherView.hidden = NO ;
           
self .tran.hidden = NO ;
            [
self .weatherView addAnimate];
            [UIView animateWithDuration:
0.2 animations:^{
               
self .rightItem.transform = CGAffineTransformRotate( self .rightItem.transform, -M_1_PI * 6 );
               
            } completion:^(
BOOL finished) {
               
                [UIView animateWithDuration:
0.1 animations:^{
                   
self .rightItem.transform = CGAffineTransformRotate( self .rightItem.transform, M_1_PI );
                }];
            }];
        }
       
self .weatherShow = ! self .isWeatherShow;
    }

   
    - (
void )pushWeatherDetail
    {
       
self .weatherShow = NO ;
        SXWeatherDetailVC *wdvc = [[SXWeatherDetailVC alloc]init];
        wdvc.weatherModel =
self .weatherModel;
        [
self .navigationController pushViewController:wdvc animated: YES ];
        [UIView animateWithDuration:
0.1 animations:^{
           
self .weatherView.alpha = 0 ;
        } completion:^(
BOOL finished) {
           
self .weatherView.alpha = 0.9 ;
           
self .weatherView.hidden = YES ;
           
self .tran.hidden = YES ;
        }];
    }
   
   
   
// ------ 下拉刷新
    - (
void )loadData
    {
       
// http://c.m.163.com//nc/article/headline/T1348647853363/0-30.html
        NSString *allUrlstring = [NSString stringWithFormat:
@"/nc/article/%@/0-20.html" , self .urlString];
        [
self loadDataForType: 1 withURL:allUrlstring];
    }
   
   
// ------ 上拉加载
    - (
void )loadMoreData
    {
        NSString *allUrlstring = [NSString stringWithFormat:
@"/nc/article/%@/%ld-20.html" , self .urlString,( self .arrayList.count - self .arrayList.count% 10 )];
       
//    NSString *allUrlstring = [NSString stringWithFormat:@"/nc/article/%@/%ld-20.html",self.urlString,self.arrayList.count];
        [
self loadDataForType: 2 withURL:allUrlstring];
    }

   
   
   
   
   
#pragma mark - /************************* tbv 数据源方法 ***************************/
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
       
return self .arrayList.count;
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        SXNewsModel *newsModel =
self .arrayList[indexPath.row];
       
        NSString *ID = [SXNewsCell idForRow:newsModel];
       
       
if ((indexPath.row% 20 == 0 )&&(indexPath.row != 0 )) {
            ID =
@"NewsCell" ;
        }
       
        SXNewsCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
       
        cell.NewsModel = newsModel;
       
       
return cell;
       
    }
   
#pragma mark - /************************* tbv 代理方法 ***************************/
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        SXNewsModel *newsModel =
self .arrayList[indexPath.row];
       
        CGFloat rowHeight = [SXNewsCell heightForRow:newsModel];
       
       
if ((indexPath.row% 20 == 0 )&&(indexPath.row != 0 )) {
            rowHeight =
80 ;
        }
       
       
return rowHeight;
    }
   
    - (
void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
       
// 刚选中又马上取消选中,格子不变色
        [tableView deselectRowAtIndexPath:indexPath animated:
YES ];
       
        UIViewController *vc = [[UIViewController alloc]init];
        vc.view.backgroundColor = [UIColor yellowColor];
    }

   
   
   
#pragma mark - /************************* 在这里做完实验就不用了 ***************************/
    - ( void )touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
       
       
// url  http://c.m.163.com/nc/article/headline/T1348647853363/full.html
       
// http://c.m.163.com/nc/article/headline/T1348647853363/0-30.html
       
       
// netconnect
        [[[SXNetworkTools sharedNetworkTools]GET:
@"nc/article/headline/T1348647853363/0-20.html" parameters: nil success:^(NSURLSessionDataTask *task, NSDictionary* responseObject) {
           
           
// 取出第一个数组,扩展性好的
            NSString *key = [responseObject.keyEnumerator nextObject];
           
            NSArray *temArray = responseObject[key];
           
           
// 取出小的一组 遍历打印出声明
            [
self writeInfoWithDict:temArray[ 1 ]];
           
            NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:temArray.count];
            [temArray enumerateObjectsUsingBlock:^(
id obj, NSUInteger idx, BOOL *stop) {
               
                NSLog(
@"===== %tu" ,idx);
                SXNewsModel *news = [SXNewsModel newsModelWithDict:obj];
                [arrayM addObject:news];
            }];
           
self .arrayList = arrayM;
           
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            NSLog(
@"%@" ,error);
        }] resume];
       
    }
   
#pragma mark - ******************** 通过此方法打印出成员变量
    - ( void )writeInfoWithDict:(NSDictionary *)dict
    {
        NSMutableString *strM = [NSMutableString string];
       
        [dict enumerateKeysAndObjectsUsingBlock:^(
id key, id obj, BOOL *stop) {
            NSLog(
@"%@,%@" ,key,[obj class]);
           
            NSString *className = NSStringFromClass([obj class]) ;
           
           
if ([className isEqualToString: @"__NSCFString" ] | [className isEqualToString: @"__NSCFConstantString" ] ) {
                [strM appendFormat:
@"@property (nonatomic,copy) NSString *%@;\n" ,key];
            }
else if ([className isEqualToString: @"__NSCFArray" ]){
                [strM appendFormat:
@"@property (nonatomic,strong)NSArray *%@;\n" ,key];
            }
else if ([className isEqualToString: @"__NSCFNumber" ]){
                [strM appendFormat:
@"@property (nonatomic,copy)NSNumber *%@;\n" ,key];
            }
else if ([className isEqualToString: @"__NSCFBoolean" ]){
                [strM appendFormat:
@"@property (nonatomic,assign)BOOL %@;\n" ,key];
            }
           
            NSLog(
@"\n%@" ,strM);
        }];
       

   
   
        - (
void )setNewsModel:(SXNewsModel *)NewsModel
        {
            _NewsModel = NewsModel;
           
           
//    [self.imgIcon sd_setImageWithURL:[NSURL URLWithString:self.NewsModel.imgsrc]];
           
            [
self .imgIcon sd_setImageWithURL:[NSURL URLWithString: self .NewsModel.imgsrc] placeholderImage:[UIImage imageNamed: @"302" ]];
           
self .lblTitle.text = self .NewsModel.title;
           
self .lblSubtitle.text = self .NewsModel.digest;
           
           
// 如果回复太多就改成几点几万
            CGFloat count =  [
self .NewsModel.replyCount intValue];
            NSString *displayCount;
           
if (count > 10000 ) {
                displayCount = [NSString stringWithFormat:
@"%.1f 万跟帖 " ,count/ 10000 ];
            }
else {
                displayCount = [NSString stringWithFormat:
@"%.0f 跟帖 " ,count];
            }
           
self .lblReply.text = displayCount;
           
           
// 多图 cell
           
if ( self .NewsModel.imgextra.count == 2 ) {
               
               
//        [self.imgOther1 sd_setImageWithURL:[NSURL URLWithString:self.NewsModel.imgextra[0][@"imgsrc"]]];
               
//        [self.imgOther2 sd_setImageWithURL:[NSURL URLWithString:self.NewsModel.imgextra[1][@"imgsrc"]]];
               
                [
self .imgOther1 sd_setImageWithURL:[NSURL URLWithString: self .NewsModel.imgextra[ 0 ][ @"imgsrc" ]] placeholderImage:[UIImage imageNamed: @"302" ]];
                [
self .imgOther2 sd_setImageWithURL:[NSURL URLWithString: self .NewsModel.imgextra[ 1 ][ @"imgsrc" ]] placeholderImage:[UIImage imageNamed: @"302" ]];
            }
           
        }
       
       
// 跟帖
        - (
void )setNewsModel:(SXNewsModel *)NewsModel
        {
            _NewsModel = NewsModel;
           
           
//    [self.imgIcon sd_setImageWithURL:[NSURL URLWithString:self.NewsModel.imgsrc]];
           
            [
self .imgIcon sd_setImageWithURL:[NSURL URLWithString: self .NewsModel.imgsrc] placeholderImage:[UIImage imageNamed: @"302" ]];
           
self .lblTitle.text = self .NewsModel.title;
           
self .lblSubtitle.text = self .NewsModel.digest;
           
           
// 如果回复太多就改成几点几万
            CGFloat count =  [
self .NewsModel.replyCount intValue];
            NSString *displayCount;
           
if (count > 10000 ) {
                displayCount = [NSString stringWithFormat:
@"%.1f 万跟帖 " ,count/ 10000 ];
            }
else {
                displayCount = [NSString stringWithFormat:
@"%.0f 跟帖 " ,count];
            }
           
self .lblReply.text = displayCount;
           
           
// 多图 cell
           
if ( self .NewsModel.imgextra.count == 2 ) {
               
               
//        [self.imgOther1 sd_setImageWithURL:[NSURL URLWithString:self.NewsModel.imgextra[0][@"imgsrc"]]];
               
//        [self.imgOther2 sd_setImageWithURL:[NSURL URLWithString:self.NewsModel.imgextra[1][@"imgsrc"]]];
               
                [
self .imgOther1 sd_setImageWithURL:[NSURL URLWithString: self .NewsModel.imgextra[ 0 ][ @"imgsrc" ]] placeholderImage:[UIImage imageNamed: @"302" ]];
                [
self .imgOther2 sd_setImageWithURL:[NSURL URLWithString: self .NewsModel.imgextra[ 1 ][ @"imgsrc" ]] placeholderImage:[UIImage imageNamed: @"302" ]];
            }
           
        }
       
       
       
#pragma mark - ******************** 拼接 html 语言
        - ( void )showInWebView
        {
            NSMutableString *html = [NSMutableString string];
            [html appendString:
@"<html>" ];
            [html appendString:
@"<head>" ];
            [html appendFormat:
@"<link rel=\"stylesheet\" href=\"%@\">" ,[[NSBundle mainBundle] URLForResource: @"SXDetails.css" withExtension: nil ]];
            [html appendString:
@"</head>" ];
           
            [html appendString:
@"<body>" ];
            [html appendString:[
self touchBody]];
            [html appendString:
@"</body>" ];
           
            [html appendString:
@"</html>" ];
           
            [
self .webView loadHTMLString:html baseURL: nil ];
        }
       
        - (NSString *)touchBody
        {
            NSMutableString *body = [NSMutableString string];
            [body appendFormat:
@"<div class=\"title\">%@</div>" , self .detailModel.title];
            [body appendFormat:
@"<div class=\"time\">%@</div>" , self .detailModel.ptime];
           
if ( self .detailModel.body != nil ) {
                [body appendString:
self .detailModel.body];
            }
           
// 遍历 img
           
for (SXDetailImgModel *detailImgModel in self .detailModel.img) {
                NSMutableString *imgHtml = [NSMutableString string];
               
               
// 设置 img div
                [imgHtml appendString:
@"<div class=\"img-parent\">" ];
               
               
// 数组存放被切割的像素
                NSArray *pixel = [detailImgModel.pixel componentsSeparatedByString:
@"*" ];
                CGFloat width = [[pixel firstObject]floatValue];
                CGFloat height = [[pixel lastObject]floatValue];
               
// 判断是否超过最大宽度
                CGFloat maxWidth = [UIScreen mainScreen].bounds.size.width *
0.96 ;
               
if (width > maxWidth) {
                    height = maxWidth / width * height;
                    width = maxWidth;
                }
               
                NSString *onload =
@"this.onclick = function() {"
               
"  window.location.href = 'sx:src=' +this.src;"
               
"};" ;
                [imgHtml appendFormat:
@"<img οnlοad=\"%@\" width=\"%f\" height=\"%f\" src=\"%@\">" ,onload,width,height,detailImgModel.src];
               
// 结束标记
                [imgHtml appendString:
@"</div>" ];
               
// 替换标记
                [body replaceOccurrencesOfString:detailImgModel.ref withString:imgHtml options:NSCaseInsensitiveSearch range:NSMakeRange(
0 , body.length)];
            }
           
return body;
        }
       
#pragma mark - ******************** 将发出通知时调用
        - ( BOOL )webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
        {
            NSString *url = request.URL.absoluteString;
            NSRange range = [url rangeOfString:
@"sx:src=" ];
           
if (range.location != NSNotFound) {
                NSInteger begin = range.location + range.length;
                NSString *src = [url substringFromIndex:begin];
                [
self savePictureToAlbum:src];
               
return NO ;
            }
           
return YES ;
        }
       
#pragma mark - ******************** 保存到相册方法
        - ( void )savePictureToAlbum:(NSString *)src
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:
@" 提示 " message: @" 确定要保存到相册吗? " preferredStyle:UIAlertControllerStyleActionSheet];
           
            [alert addAction:[UIAlertAction actionWithTitle:
@" 取消 " style:UIAlertActionStyleCancel handler: nil ]];
            [alert addAction:[UIAlertAction actionWithTitle:
@" 确定 " style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
               
                NSURLCache *cache =[NSURLCache sharedURLCache];
                NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:src]];
                NSData *imgData = [cache cachedResponseForRequest:request].data;
                UIImage *image = [UIImage imageWithData:imgData];
                UIImageWriteToSavedPhotosAlbum(image,
nil , nil , nil );
               
            }]];
           
           
            [
self presentViewController:alert animated: YES completion: nil ];
        }
       
#pragma mark - ******************** 即将跳转时
        - ( void )prepareForSegue:(UIStoryboardSegue *)segue sender:( id )sender
        {
            SXReplyViewController *replyvc = segue.destinationViewController;
            replyvc.replys =
self .replyModels;
           
           
if ([ self .navigationController respondsToSelector: @selector (interactivePopGestureRecognizer)]) {
               
self .navigationController.interactivePopGestureRecognizer.delegate = nil ;
            }
           
            [[NSNotificationCenter defaultCenter]postNotification:[NSNotification notificationWithName:
@"contentStart" object: nil ]];
        }
       

       
       
// 多种类型单元格
#pragma mark - /************************* 类方法返回可重用 ID ***************************/
        + (NSString *)idForRow:(SXNewsModel *)NewsModel
        {
           
if (NewsModel.hasHead && NewsModel.photosetID) {
               
return @"TopImageCell" ;
            }
else if (NewsModel.hasHead){
               
return @"TopTxtCell" ;
            }
else if (NewsModel.imgType){
               
return @"BigImageCell" ;
            }
else if (NewsModel.imgextra){
               
return @"ImagesCell" ;
            }
else {
               
return @"NewsCell" ;
            }
        }
       
#pragma mark - /************************* 类方法返回行高 ***************************/
        + (CGFloat)heightForRow:(SXNewsModel *)NewsModel
        {
           
if (NewsModel.hasHead && NewsModel.photosetID){
               
return 245 ;
            }
else if (NewsModel.hasHead) {
               
return 245 ;
            }
else if (NewsModel.imgType) {
               
return 170 ;
            }
else if (NewsModel.imgextra){
               
return 130 ;
            }
else {
               
return 80 ;
            }
        }
     
}

- (
void )didReceiveMemoryWarning {
    [
super didReceiveMemoryWarning];
   
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end

    


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值