zoukankan      html  css  js  c++  java
  • iOS-QQ好友列表 iOS 页面间几种传值方式(属性,代理,block,单例,通知)

    主要是 点击按钮实现下拉 刷新数据

    页面间传值

    //
    //  HMFriendsModel.h
    //  QQ好友列表
    //
    //  Created by YaguangZhu on 15/9/1.
    //  Copyright (c) 2015年 YaguangZhu. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @interface HMFriendsModel : NSObject
    
    
    @property(nonatomic,copy) NSString *name;
    
    @property(nonatomic,copy) NSString *icon;
    
    @property(nonatomic,copy) NSString *intro;
    
    @property(nonatomic,assign,getter=isVip) BOOL vip ;
    
    
    - (instancetype)initWithDict:(NSDictionary *)dict;
    + (instancetype)friendsWithDict:(NSDictionary *)dict;
    //+ (NSArray *)friends;
    
    @end

    //

    
    

    //  HMFriendsModel.m

    
    

    //  QQ好友列表

    
    

    //

    
    

    //  Created by YaguangZhu on 15/9/1.

    
    

    //  Copyright (c) 2015 YaguangZhu. All rights reserved.

    
    

    //

    
    

     

    
    

    #import "HMFriendsModel.h"

    
    

     

    
    

    @implementation HMFriendsModel

    
    

    - (instancetype)initWithDict:(NSDictionary *)dict

    
    

    {

    
    

        self = [super init];

    
    

        if (self) {

    
    

            [self setValuesForKeysWithDictionary:dict];

    
    

        }

    
    

        return self;

    
    

    }

    
    

     

    
    

    + (instancetype)friendsWithDict:(NSDictionary *)dict

    
    

    {

    
    

        return [[self alloc] initWithDict:dict];

    
    

    }

    
    

     

    
    

    //+ (NSArray *)friends

    
    

    //{

    
    

    //    NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"friends.plist" ofType:nil]];

    
    

    //    NSMutableArray *arrayM = [NSMutableArray array];

    
    

    //    for (NSDictionary *dict in array) {

    
    

    //        [arrayM addObject:[self friendsWithDict:dict]];

    
    

    //    }

    
    

    //    

    
    

    //    return arrayM;

    
    

    //}

    
    

     

    
    

    @end

     
    //
    //  HMFriendsGroupModel.h
    //  QQ好友列表
    //
    //  Created by YaguangZhu on 15/9/1.
    //  Copyright (c) 2015年 YaguangZhu. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @interface HMFriendsGroupModel : NSObject
    
    @property(nonatomic,strong) NSArray *friends;
    
    @property(nonatomic,copy) NSString *name;
    
    @property(nonatomic,assign) BOOL open;
    
    @property(nonatomic,assign) int online;
    
    - (instancetype)initWithDict:(NSDictionary *)dict;
    + (instancetype)friendsGroupWithDict:(NSDictionary *)dict;
    //+ (NSArray *)friendsModel;
    
    @end
    
    
    //
    //  HMFriendsGroupModel.m
    //  QQ好友列表
    //
    //  Created by YaguangZhu on 15/9/1.
    //  Copyright (c) 2015年 YaguangZhu. All rights reserved.
    //
    
    #import "HMFriendsGroupModel.h"
    #import "HMFriendsModel.h"
    @implementation HMFriendsGroupModel
    
    - (instancetype)initWithDict:(NSDictionary *)dict
    {
        
        if (self = [super init]) {
            //注入所有值
            [self setValuesForKeysWithDictionary:dict];
            
            NSMutableArray *arr = [NSMutableArray array];
            for (NSDictionary *dict in self.friends) {
                HMFriendsModel *model = [HMFriendsModel friendsWithDict:dict];
                
                [arr addObject:model];
                
            }
            
            self.friends = arr;
            
        }
        return self;
        
    //    self = [super init];
    //    if (self) {
    //        [self setValuesForKeysWithDictionary:dict];
    //    }
    //    return self;
    }
    
    + (instancetype)friendsGroupWithDict:(NSDictionary *)dict
    {
        return [[self alloc] initWithDict:dict];
    }
    
    //+ (NSArray *)friendsModel
    //{
    //    HMFriendsGroupModel *model =[[HMFriendsGroupModel alloc]init];
    //    NSMutableArray *arrayM = [NSMutableArray array];
    //    
    //            for (NSDictionary *dict in model.friends) {
    //                HMFriendsModel *model = [HMFriendsModel friendsWithDict:dict];
    //    
    //                [arrayM addObject:model];
    //            }
    //    model.friends =arrayM;
    //    
    //    return arrayM;
    //}
    
    
    @end
    //
    //  HMHeaderView.h
    //  QQ好友列表
    //
    //  Created by YaguangZhu on 15/9/5.
    //  Copyright (c) 2015年 YaguangZhu. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    @class HMHeaderView;
    
    typedef void(^HMHeaderViewBlock)(id);
    
    
    @protocol HMHeaderViewDelegate <NSObject>
    
    @optional
    - (void)headerView:(HMHeaderView *)view;
    
    
    
    @end
    
    @class HMFriendsGroupModel;
    @interface HMHeaderView : UITableViewHeaderFooterView
    
    + (instancetype)headerViewWith:(UITableView *)tableview;
    
    @property (nonatomic, assign)id<HMHeaderViewDelegate> delegate;
    
    
    @property (nonatomic, strong)HMFriendsGroupModel *group;
    
    
    @property (nonatomic, copy)HMHeaderViewBlock block;
    
    @end
    
    
    //
    //  HMHeaderView.m
    //  QQ好友列表
    //
    //  Created by YaguangZhu on 15/9/5.
    //  Copyright (c) 2015年 YaguangZhu. All rights reserved.
    //
    
    #import "HMHeaderView.h"
    #import "HMFriendsGroupModel.h"
    @interface HMHeaderView ()
    
    @property (nonatomic, weak)UIButton *nameBtn;
    
    @property (nonatomic, weak)UILabel *textLbl;
    
    @end
    
    
    @implementation HMHeaderView
    
    + (instancetype)headerViewWith:(UITableView *)tableview
    {
        
        static NSString *ID = @"headerView";
        //首先看缓存池中是否存在headerView,如果存在的 直接取出来用
        HMHeaderView *header = [tableview dequeueReusableHeaderFooterViewWithIdentifier:ID];
        
        if (header == nil) {
            //如果不存在   重新创建一个
            header = [[HMHeaderView alloc]initWithReuseIdentifier:ID];
        }
        
        return header;
    }
    
    - (void)setGroup:(HMFriendsGroupModel *)group
    {
        
        //1. 必须做的操作
        _group = group;
        
        
        [self.nameBtn setTitle:group.name forState:UIControlStateNormal];
        
        //显示在线人数
        self.textLbl.text = [NSString stringWithFormat:@"%d/%d",group.online,group.friends.count];
        
    }
    
    
    //  当headerview 上子控件只需 做一次操作的  或者  要显示出来的    就写在以下方法中
    - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier
    {
        if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
            
            // Custom  相当  [[UIButton alloc]init];
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            //btn 上面有一个imageView
            [btn setImage:[UIImage imageNamed:@"buddy_header_arrow"] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            //设置按钮内容的居左显示
            btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            //设置按钮的内边距
            btn.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
            //设置按钮 label 的 内边距
            btn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
            //按钮内部 imageview 的内边距
            //        btn.imageEdgeInsets
            //居中显示
            btn.imageView.contentMode = UIViewContentModeCenter;
            
            //不予许剪切超出部分
            btn.imageView.clipsToBounds = NO;
            
            
            [btn addTarget:self action:@selector(nameBtnClick) forControlEvents:UIControlEventTouchUpInside];
            
            [self addSubview:btn];
            self.nameBtn = btn;
            
            NSLog(@"---------%@",NSStringFromCGRect(self.contentView.frame));
            
            
            UILabel *lable = [[UILabel alloc]init];
            
            //居右显示
            lable.textAlignment = NSTextAlignmentRight;
            
            [self.contentView addSubview:lable];
            
            self.textLbl = lable;
            
        }
        
        
        
        
        return self;
    }
    
    /**
     *  当 当前的view 的frame 发生一些改变的时候  调用次方法  重新布局  内部的子控件
     */
    - (void)layoutSubviews
    {
        self.nameBtn.frame = self.bounds;
        //获取屏幕的宽度
        //    CGFloat screenW = [[UIScreen mainScreen] bounds].size.width;
        
        CGFloat lblY = 0;
        CGFloat lblW = 150;
        CGFloat lblh = self.frame.size.height;
        CGFloat lblX = self.frame.size.width - lblW - 10;
        
        self.textLbl.frame = CGRectMake(lblX, lblY, lblW, lblh);
        
    }
    
    /**
     *  代理方法
     */
    - (void)nameBtnClick
    {
        self.group.open = !self.group.open;
        
    //        if ([self.delegate respondsToSelector:@selector(headerView:)]) {
    //            [self.delegate headerView:self];
    //        }
    //
    //    
    //    
    //    
    //    if (self.block) {
    //        self.block(self);
    //    }
        
    //
       [[NSNotificationCenter defaultCenter] postNotificationName:@"friend" object:self userInfo:nil];
        
        
        
        NSLog(@"----------------");
    }
    
    
    
    /**
     *  当 当前的view 加载到父控件的时候调用
     */
    - (void)didMoveToSuperview
    {
        
        //每次当控件加载到父控件的时候都会调用这个方法,包括init 完一次就会调用一次
        if (self.group.open) {
            self.nameBtn.imageView.transform = CGAffineTransformMakeRotation(M_PI_2);
            
            NSLog(@"999999999");
            
        }else{
            self.nameBtn.imageView.transform = CGAffineTransformMakeRotation(0);
        }
        
    }
    
    @end
  • 相关阅读:
    cef加载flash的办法
    一个高性能的对象属性复制类,支持不同类型对象间复制,支持Nullable<T>类型属性
    php检测php.ini是否配制正确
    openwrt的路由器重置root密码
    windows 7 + vs2010 sp1编译 x64位版qt4
    解决SourceGrid在某些系统上无法用鼠标滚轮滚动的问题
    判断一个点是否在多边形内部,射线法思路,C#实现
    [转载]使用HttpWebRequest进行请求时发生错误:基础连接已关闭,发送时发生错误处理
    让Dapper+SqlCE支持ntext数据类型和超过4000字符的存储
    通过WMI
  • 原文地址:https://www.cnblogs.com/zhuyaguang/p/4783887.html
Copyright © 2011-2022 走看看