IOS学习笔记之获取Plist文件读取数据

@property(nonatomic,strong) NSArray *pic; //创建数组属性
@property(nonatomic,assign) int index;    //创建索引属性
@property (strong, nonatomic) IBOutlet UIImageView *imageIcon; //列表上的UIImageView

- (void)viewDidLoad
{
  
  [super viewDidLoad];
   
//首次加载时调用数据方法,让index显示第0的图片数据
   [self DataInfoSoure];

}
//----------懒加载-------------- -(NSArray *) pic {  //每次加载时判断Pic是否有值 if (_pic ==nil) { //重写Pic属性的Get方法 //获取Plist路径搜索Plist文件并赋值给path NSString *Path =[[NSBundle mainBundle] pathForResource:@"plistIcon.plist" ofType:nil]; //读取文件 NSArray * array =[NSArray arrayWithContentsOfFile:Path]; //把数据赋值给属性 _pic =array; } return _pic; } //上一张 - (IBAction)pre { //让索引++ self.index--; [self DataInfoSoure]; //判断是否是最后一张,返回YES/NO self.nextsx.enabled =self.index!=self.pic.count-1; //设置控件数据 self.presx.enabled= self.index!=0; } //下一张 - (IBAction)next { self.index++; [self DataInfoSoure]; self.nextsx.enabled =self.index!=self.pic.count-1; self.presx.enabled= self.index!=0; } -(void)DataInfoSoure { //从数组中获取当前这张图片的数据 NSDictionary *dict= self.pic[self.index]; // 获取到的数据设置给界面上的控件 self.labIcon.text = [NSString stringWithFormat:@"%d,%ld",self.index+1, (unsigned long)self.pic.count]; //通过image属性来设置图片框里的图片 self.imageIcon.image = [UIImage imageNamed:dict[@"Icon"]]; //设置这张图片的标题 self.labtitle.text =dict[@"title"]; }

 

posted @ 2015-09-11 08:24  一望无际的大海  阅读(638)  评论(0编辑  收藏  举报