待整理

Xcode文件夹

Scenes/ViewController
PersonTableViewController.m


@property (nonatomic, retain) NSMutableDictionary *allDataDict;
@property (nonatomic, retain) NSMutableArray *allKeysArray; // 保存排序好的所有key值


//#pragma mark - 加载数据
- (void)loadData
{
    // 1. 找到文件在包中的路径
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Class150102AllStudents" ofType:@"plist"];
    // 2. 根据路径,读取文件
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filePath];
    NSLog(@"%@", dict);

     // 3. 将读取出来的数据,存入到新的可变字典里
    self.allDataDict = [NSMutableDictionary dictionary];

    // 3.1 遍历原字典中的所有key值
    for (NSString *key in dict.allKeys) {
        // 3.2 有一个key就应该有一个对应的可变数组
        NSMutableArray *mutableArray = [NSMutableArray array];

        // 3.4 遍历原字典中的数组中的小数组
        for (NSDictionary *item in dict[key]) {
            // 3.5 将item小字典,转化为Person对象
            Person *p = [[Person new] autorelease];
            [p setValuesForKeysWithDictionary:item];  // 通过字典,设置p对象属性的值

            // 3.6 将转好的p对象添加到可变数组中
            [mutableArray addObject:p];
        }


        // 3.3 添加到可变数组中
        [_allDataDict setObject:mutableArray forKey:key];

    }

    // 4. 获取到所有的key值,然后排序
    self.allKeysArray = [NSMutableArray arrayWithArray:_allDataDict.allKeys];
    // 使用block排序
    [_allKeysArray sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
        if ([obj1 compare:obj2] == NSOrderedDescending) {
            return 1;
        }
        return 0;
    }];
}

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

    static NSString *Identifier = @"asd";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
    if (!cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Identifier] autorelease];
    }

    NSString *key = _allKeysArray[indexPath.section];

    NSMutableArray * array = _allDataDict[key];

    Person *p = array[indexPath.row];

    cell.textLabel.text = p.name;

    cell.imageView.image = [UIImage imageNamed:p.headImageName];
    cell.detailTextLabel.text = p.phoneNumber;

    // 显示 详情符号
    cell.accessoryType = UITableViewCellAccessoryDetailButton;

    return cell;
}
  1. 继承UITableViewCell,写了BoyCell
  2. 在BoyCell.h声明属性
  3. dealloc / 创建并且添加了

  4. 在PersonTableViewControlller.m中引入 BoyCell.h 文件

  5. 将每行显示什么内容方法中的UITableViewCell替换成了BoyCell
  6. cell.nameLabel.text = p.name; ….

  7. 在BoyCell.h中声明Person类,并且声明了Person属性

  8. 在BoyCell.m中重写perosn属性的setter方法,然后将person参数上的值,赋给了页面上
  9. 在外界,直接通过 cell.person = p; 实现cell的赋值

  10. 实现了计算文字高度的方法

  11. 在重写的setter方法中,计算了自我介绍文字的高度,并修改了_introduceLabel的高度

  12. 在BoyCell.h文件中声明了计算cell高度的方法,并实现

  13. 在设置cell高度的代理方法中使用BoyCell提供的计算cell高度的方法,得到cell应该的高度,并返回
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值