uitableview持续练习
来源:互联网 发布:三维游戏制作软件 编辑:程序博客网 时间:2024/06/05 17:04
<span style="color:#ff0000;">对于我而言比较容易犯的几个错误:</span>
<span style="color:#ff0000;">(1)uitableview没有拖线跟相应的界面联系;</span>
<span style="color:#ff0000;">(2)self.tableview.datasource = self;//不能设置</span>
<span style="color:#ff0000;">(3)plist文件名有可能写错。</span>
<span style="color:#ff0000;"></span>
<span style="color:#ff0000;">!!!最重要一点是:数组的大小,如返回_heros.count会是0,但是返回self.heros.count则正常的。</span>
<span style="color:#ff0000;">表示应该是一个@property等的调用机制的问题。(这个有点难发现)。</span>
//// MJViewController.m// 04-英雄展示//// Created by apple on 14-3-30.// Copyright (c) 2014年 itcast. All rights reserved.//#import "MJViewController.h"#import "MJHero.h"@interface MJViewController () <UITableViewDataSource, UITableViewDelegate>@property (nonatomic, strong) NSArray *heros;@property (weak, nonatomic) IBOutlet UITableView *tableView;@end@implementation MJViewController- (void)viewDidLoad{ [super viewDidLoad]; }- (NSArray *)heros{ if (_heros == nil) { // 初始化 // 1.获得plist的全路径 NSString *path = [[NSBundle mainBundle] pathForResource:@"heros.plist" ofType:nil]; // 2.加载数组 NSArray *dictArray = [NSArray arrayWithContentsOfFile:path]; // 3.将dictArray里面的所有字典转成模型对象,放到新的数组中 NSMutableArray *heroArray = [NSMutableArray array]; for (NSDictionary *dict in dictArray) { // 3.1.创建模型对象 MJHero *hero = [MJHero heroWithDict:dict]; // 3.2.添加模型对象到数组中 [heroArray addObject:hero]; } // 4.赋值 _heros = heroArray; } return _heros;}#pragma mark - 数据源方法- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.heros.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:nil]; // 取出模型 MJHero *hero = self.heros[indexPath.row]; // 设置cell的数据 cell.textLabel.text = hero.name; cell.detailTextLabel.text = hero.intro; cell.imageView.image = [UIImage imageNamed:hero.icon]; // 设置cell右边指示器的类型// if (indexPath.row % 2 == 0) { cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;// } // cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;// cell.accessoryView = [[UISwitch alloc] init]; // 设置背景(背景view不用设置尺寸, backgroundView的优先级 > backgroundColor) UIImageView *bgView = [[UIImageView alloc] init]; bgView.image = [UIImage imageNamed:@"buttondelete"];// bgView.backgroundColor = [UIColor redColor]; cell.backgroundView = bgView; UIView *selectedbgView = [[UIView alloc] init]; selectedbgView.backgroundColor = [UIColor greenColor]; cell.selectedBackgroundView = selectedbgView; return cell;}#pragma mark - 代理方法- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 60;}@end
0 0
- uitableview持续练习
- UITableView练习-省市区
- UITableView练习一
- Cocos2dx练习,持续更新。
- auto layout 练习 - 持续
- 第二十二篇:UITableView练习代码
- UITableView练习二之Dynamic Prototypes练习
- 【原创,持续更新】正则练习
- UITableView练习三之Static Cells
- 练习:UITableView 下做图片放大
- UITableView使用大全-表视图合集-持续更新
- UITableView与UIScrollView的一些问题(持续更新)
- UITableView与UIScrollView的一些问题(持续更新)
- 关于UITableView的一些细小的知识点总结(持续更新)
- 最近练习的一些算法(持续更新)
- 正则表达式练习,持续更新中
- 蓝桥杯练习系统试题持续更新
- CTF-练习平台writeup【持续更新】
- C++打印个乘法表玩玩
- android之asset资源
- HMMStateArc API
- 顶点间最短路径长度之探寻算法
- IIS打不开网站
- uitableview持续练习
- 点乘与叉乘
- HMMState API
- Java基础_基础知识
- Linux下装Eclipse C/C++,以及环境配置
- 混合高斯背景建模
- HMM API
- Django知识点总结(一)
- 写一个程序用来查询手机号码的归属地(使用的是HttpURLConnection的get提交方式)