您的位置:首页 > 编程语言

优化代码结构笔记

2016-02-23 15:17 344 查看
静态的DataSource - 使用Plist来设置静态资源。

NSString *shopListPath = [[NSBundle mainBundle]pathForResource:@"shop" ofType:@"plist"];
self.shops = [[NSArray alloc]initWithContentsOfFile:shopListPath];


#pragma mark - TableView DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray *sectionArray = self.shops[section];
return sectionArray?sectionArray.count:0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.shops?self.shops.count:0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];

NSArray *sectionArray = self.shops[indexPath.section];
NSDictionary *shopDict = sectionArray[indexPath.row];

cell.textLabel.text = shopDict[@"title"];
cell.detailTextLabel.text = shopDict[@"content"];

return cell;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  plist 优化