zoukankan      html  css  js  c++  java
  • UITableView读取plist文件

    一、plist文件详情

    二、UITableView读取plist文件代码 

    #import "ViewController.h"

    @interfaceViewController ()

    {

        NSArray *_data;

    }

    @end

    @implementation ViewController

    - (void)viewDidLoad

    {

        [superviewDidLoad];

        _data = [NSArrayarrayWithContentsOfFile:[[NSBundlemainBundle] pathForResource:@"360app.plist"ofType:nil]];

        

    //    NSMutableArray *array = [NSMutableArray array];

    //    

    //    for (int i = 0; i<_data.count; i++) {

    //        NSDictionary *oldDict = _data[i];

    //        

    //        NSMutableDictionary *newDict = [NSMutableDictionary dictionary];

    //        [newDict setDictionary:oldDict];

    //        [newDict setObject:[NSString stringWithFormat:@"%d.png", i] forKey:@"local_icon"];

    //        

    //        [array addObject:newDict];

    //    }

    //    

    //    [array writeToFile:@"/Users/apple/Desktop/360app.plist" atomically:YES];

        

    //    NSLog(@"%d", _data.count);

    //    for (int i = 0; i<_data.count; i++) {

    ////        NSLog(@"------");

    //        NSDictionary *app = _data[i];

    //        

    //        NSLog(@"%@", app[@"icon"]);

    //        

    //        NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:app[@"icon"]]];

    //        

    //        NSString *filename = [NSString stringWithFormat:@"/Users/apple/Desktop/360img/%d.png", i];

    //        [imgData writeToFile:filename atomically:YES];

    //    }

    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    {

        return _data.count;

    }

    #pragma mark 每当有一个cell进入视野范围内就会调用,返回当前这行显示的cell

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        // 0.static修饰的局部变量,只会初始化一次

        static NSString *ID = @"cell";

        

        // 1.拿到一个标识先去缓存池中查找对应的Cell

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

        

        // 2.如果缓存池中没有,才需要传入一个标识创建新的Cell

        if (cell == nil) {

            cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:ID];

        }

        

        // 3.覆盖数据

        NSDictionary *app = _data[indexPath.row];

        

    //    NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:app[@"icon"]]];

    //    NSString *filename = [NSString stringWithFormat:@"%d.png", indexPath.row];

        cell.imageView.image = [UIImage imageNamed:app[@"local_icon"]];

        cell.textLabel.text = app[@"name"];

        cell.detailTextLabel.text = app[@"download"];

        

        return cell;

    }

    @end

  • 相关阅读:
    python爬虫23 | 手机,这次要让你上来自己动了。这就是 Appium+Python 的牛x之处
    python爬虫22 | 以后我再讲python「模拟登录」我就是狗
    python爬虫21 | 对于b站这样的滑动验证码,不好意思,照样自动识别
    phpcms 之 日期时间标签的调用
    phpcms 友情链接的调用
    在网页中嵌入百度地图的步骤(转)
    jquery 怎么取select选中项 自定义属性的值
    PHP实现根据银行卡号判断银行
    数据库基础
    从输入网址到显示网页的过程中发生了什么?(转自88旧港)
  • 原文地址:https://www.cnblogs.com/changxs/p/3484919.html
Copyright © 2011-2022 走看看