小编实在不想多说什么了,直接上代码吧.我觉得我的主要注释写的已经很清楚了.
在此说明小编这里用的是xib的写法,如果在其中的运行中有什么问题,请放心评论,我会在第一时间为大家解答.谢谢支持
代码案例
1.#import <UIKit/UIKit.h>
@interface ZJStatuesTableViewController : UITableViewController
@end
2.#import "ZJStatuesTableViewController.h"
#import "ZJStatuesTableViewCell.h"
#import "ZJStatus.h"
@interface ZJStatuesTableViewController ()
/** 存放数据的数组 */
@property (strong, nonatomic) NSArray *statuses;
@end
@implementation ZJStatuesTableViewController
/**
* 懒加载
*
*/
- (NSArray *)statuses
{
if (_statuses == nil) {
// 加载plist中的字典数组
NSString *path = [[NSBundle mainBundle] pathForResource:@"statuses.plist" ofType:nil];
NSArray *dictArray = [NSArray arrayWithContentsOfFile:path];
// 字典数组 -> 模型数组
NSMutableArray *statusArray = [NSMutableArray array];
for (NSDictionary *dict in dictArray) {
ZJStatus *status = [ZJStatus statusWithDict:dict];
[statusArray addObject:status];
}
_statuses = statusArray;
}
return _statuses;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// 返回多少行,通过数组中的个数