与手写纯代码主要区别:
1、组件初始化拖拽完成
2、VC设置中有变化
3、不需要设置实体类存放属性数据
步骤1、ViewController中设置展示cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dic = [self.qiquanArray objectAtIndex:indexPath.section];
//第1种方法,不同cell文件设置
if ([dic[@"optionType"] isEqualToString:@"S"])
{
static NSString *CellIdentifier = @"DateOptionCell_S";
TwoDeBaoCell *cell = (TwoDeBaoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (nil == cell)
{
cell = (TwoDeBaoCell *)[[[NSBundle mainBundle]loadNibNamed:@"TwoDeBaoCell" owner:self options:nil]lastObject];
}
//赋值方法
[cell setValueOfCell:dic];
return cell;
}
//第2中方法:相同文件中设置不同cell
DateOptionCell *cell;
if([dic[@"optionType"] isEqualToString:@"B"])
{
static NSString *CellIdentifier = @"DateOptionCell_B";
cell = (DateOptionCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (nil == cell)
{
cell = (DateOptionCell *)[[[NSBundle mainBundle]loadNibNamed:@"DateOptionCell" owner:self options:nil]objectAtIndex:0];
}
}
else
{
static NSString *CellIdentifier = @"DateOptionCell_C";
cell = (DateOptionCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (nil == cell)
{
cell = (DateOptionCell *)[[[NSBundle mainBundle]loadNibNamed:@"DateOptionCell" owner:self options:nil]lastObject];
}
}
//界面赋值(也可以使用设置方法,在cell.m中赋值)
if([dic[@"optionType"] isEqualToString:@"B"])
{
cell.buyUpLab.attributedText = [StaticTools compareAngsi:dic[@"currencyPairId"] andAttributedString:dic[@"custcallBid"]];
cell.sellUpLab.attributedText = [StaticTools compareAngsi:dic[@"currencyPairId"] andAttributedString:dic[@"custcallOffer"]];
cell.buyDownLab.attributedText = [StaticTools compareAngsi:dic[@"currencyPairId"] andAttributedString:dic[@"custputBid"]];
cell.sellDownLab.attributedText = [StaticTools compareAngsi:dic[@"currencyPairId"] andAttributedString:dic[@"custputOffer"]];
}
else
{ //
if([dic[@"callorput"] isEqualToString:@"C"]){
cell.downImgView.hidden = YES;
cell.downLab.hidden = YES;
cell.buyLab.attributedText = [StaticTools compareAngsi:dic[@"currencyPairId"] andAttributedString:dic[@"custcallBid"]];
cell.sellLab.attributedText = [StaticTools compareAngsi:dic[@"currencyPairId"] andAttributedString:dic[@"custcallOffer"]];
}
else
{
cell.upImgView.hidden = YES;
cell.upLab.hidden = YES;
cell.buyLab.attributedText = [StaticTools compareAngsi:dic[@"currencyPairId"] andAttributedString:dic[@"custputBid"]];
cell.sellLab.attributedText = [StaticTools compareAngsi:dic[@"currencyPairId"] andAttributedString:dic[@"custputOffer"]];
cell.buyLab.textColor = cell.sellLab.textColor = RGBCOLOR(28, 126, 52);
}
}
步骤2、
cell拖拽属性时:方法1比较随意,一般方法即可。
方法2的时候,相同属性拖拽到同一个属性名称上也可以,拖拽不同名称也可以;
注意拖拽后要点击cell视图查看连接,如不成功则需从右侧边栏拖拽到控件上。
具体方法及动图详见博客:http://blog.csdn.net/kepoon/article/details/52302862
网友评论