KVC的步骤 以及重点

MVC的步骤 以及重点 


Contriller.m


#import "MusickPlayTableController.h"
#import "MusickListCell.h"
#import "MusickModel.h"
@interface MusickPlayTableController ()
@property(nonatomic,retain)NSArray*dataArray;
@property(nonatomic,retain) NSMutableArray *musicArray;
@end

@implementation MusickPlayTableController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"听风";
   
    NSURL*url = [NSURL URLWithString:@"http:project.lanou3g.com/teacher/UIAPI/MusicInfoList.plist"];
    
    NSURLRequest*ruquest = [NSURLRequest requestWithURL:url cachePolicy:0 timeoutInterval:5.0];
    
    //网络请求
    [NSURLConnection sendAsynchronousRequest:ruquest queue:[[NSOperationQueue alloc ]init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError) {
            NSLog(@"错误 %@",connectionError);
            
            return ;
            
            
        }
 
        //data 是一个plisst 数据,对data进行 反序列化解写
        _dataArray=[NSPropertyListSerialization propertyListWithData:data options:0 format:NULL error:NULL];
        _musicArray = [NSMutableArray array];
        for (NSDictionary * dic in _dataArray) {
            NSLog(@"%@",dic);
            MusickModel*model=[[MusickModel alloc] init];
            
        
            [model setValuesForKeysWithDictionary:dic];  //必须写 否则赋不上值
       
            [_musicArray addObject:model]; //必须写 否则赋不上值

//            NSLog(@"%@",model.singer);
            
            
        }
        
        [self.tableView reloadData];
        
        //从新加载
        
      // [self.tableView reloadData];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            //            //.....
                    });

 
    }];
     
     
    
}


///

View.m





#import "MusickListCell.h"

@implementation MusickListCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self =[ super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        //歌曲名
        CGRect  rect1=CGRectMake(180, 20, 200, 40);
        
        _SongNameLabel=[[UILabel alloc] initWithFrame:rect1];
        
        _SongNameLabel.backgroundColor=[UIColor redColor];
        
        [self addSubview:_SongNameLabel];
        //歌者名
         CGRect  rect2=CGRectMake(180, 70, 200, 40);
        
        _SingerNameLabel=[[UILabel alloc] initWithFrame:rect2];
        
        _SingerNameLabel.backgroundColor=[UIColor greenColor];
        
        [self addSubview: _SingerNameLabel];
        
        //歌手头像
          CGRect  rect3=CGRectMake(0, 0, 100, 200);
        
        _SingerPhtoto=[[UIImageView alloc] initWithFrame:rect3];
        
        _SingerPhtoto.backgroundColor=[UIColor yellowColor];
        
        [self addSubview:_SingerPhtoto];
        
        
    }
    return self;
}

#pragma 数据模型赋值方法
-(void)setMusickMoudel:(MusickModel *)musickMoudel
{
    if (_musickMoudel!=musickMoudel) {
        
//        _musickMoudel=[musickMoudel retain];
        _SingerNameLabel.text=musickMoudel.artists_name;
        
        _SongNameLabel.text=musickMoudel.name;
        
        _SingerPhtoto.image =musickMoudel.picUrl;
        
    }
}

- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

@end
/

mosel.m



#import "MusickModel.h"

@implementation MusickModel




-(void)setValue:(id)value forKey:(NSString *)key
{
    //父类方法 必须写 否则赋不上值
    [super setValue:value forKey:key];

    
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    //防止蹦亏
}
@end








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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值