懒加载数据,在取出数据是容易出的bug....

NSDictionary *dict=self.picture[self.index];
    self.jieshaoLabel.text=dict[@"desc"];
    self.imageViewIcon.image=[UIImage imageNamed:dict[@"icon"]];
    self.suoyinLabel.text=[NSString stringWithFormat:@"%d / %ld",self.index+1,self.picture.count];

&1.易错点bug: 为什么第二行代码这里不用NSString stringWithFormat:?

       //取出数组的数据,因为数据是字典,所以用字典接收

    NSDictionary *dict=self.picture[self.index];

    self.jieshaoLabel.text=dict[@"desc"];

      //==等效于[NSString stringWithFormat:@"%@",dict[@"desc"]];

       第一种解释:这里使用的就是里面的属性, 所以可以直接用,

    //?? 为什么这里不用NSString stringWithFormat:

       第二种解释:  因为这里直接就可以引用字典中的键值对的数据了,而下面的self.suoyinLabel.text需要拼接组合数据,需要通过调用其他的属性来组成,所以需要用;

    self.imageViewIcon.image=[UIImage imageNamed:dict[@"icon"]];

    self.suoyinLabel.text=[NSString stringWithFormat:@"%d / %ld",self.index+1,self.picture.count];

&2.易出bug的地方: @"%ld” self.picture.count;    这里比较容易出现错误,那就是当你的模拟器是选择5s及其以后版本的模拟器的时候,模拟器属于64位系统,那么就要用%ld,如果是选择的5及其之前的模拟器,模拟器属于32位系统,那么就要用%d


你可能感兴趣的:(懒加载数据,在取出数据是容易出的bug....)