zoukankan      html  css  js  c++  java
  • 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"]; }
  • 相关阅读:
    问题解决(2)
    问题解决(1)
    ubuntu16.04spyder闪退
    ubuntu16.04安装caffe
    python做批量剪切、旋转等小程序
    html中如何使得改变背景的透明度时,背景上的文字透明度不被改变
    css下拉菜单制作
    float浮动
    css盒子模型
    css选择器,背景样式,文本属性
  • 原文地址:https://www.cnblogs.com/zzgt/p/4799881.html
Copyright © 2011-2022 走看看