IOS學習筆記之擷取Plist檔案讀取資料

來源:互聯網
上載者:User

標籤:

@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"];}

 

IOS學習筆記之擷取Plist檔案讀取資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.