Al03's blog

DynamicPrototypesTable

使用视图文件自定义较复杂的UITableViewCell,之前的做法是先做一个UITableViewCell的子类,然后再做一个以uitableviewcellviewviewcontroller。后有了storyboard,在里面UITableViewcontent有两个属性Dynamic Prototypesstatic cells,至于这两个的区别Dynamic Prototypes属性支持重用,static cells就不介绍了,它连UITableViewDataSource的方法都不用。

设置UITabelView

![image](/images/DynamicPrototypesTable/Screen Shot 2014-02-10 at 11.29.51 AM.png)

向UITabelView添加cell和cell的内容

![image](/images/DynamicPrototypesTable/Screen Shot 2014-02-12 at 5.26.38 PM.png)

这步很爽有木有。然后设置不同样式cellIdentifier

![image](/images/DynamicPrototypesTable/Screen Shot 2014-02-10 at 11.42.23 AM.png)

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

static NSString *strCellId;
if (indexPath.row == 0) {
    strCellId = @"cellSlider";
}else if (indexPath.row == 1){
    strCellId = @"cellSegmented";
}else{
    strCellId = @"cellSwitch";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCellId];
return cell;
}

![image](/images/DynamicPrototypesTable/iOS Simulator Screen shot Feb 12, 2014, 5.33.17 PM.png)

cell内的信息设置

做一个UITableViewCell子类

![image](/images/DynamicPrototypesTable/Screen Shot 2014-02-10 at 11.42.05 AM.png)

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

static NSString *strCellId;
if (indexPath.row == 0) {
    strCellId = @"cellSlider";
}else if (indexPath.row == 1){
    strCellId = @"cellSegmented";
}else{
    strCellId = @"cellSwitch";
}
DynamicPrototypesCell *cell = [tableView dequeueReusableCellWithIdentifier:strCellId];

//set cell source
if ([strCellId isEqualToString:@"cellSlider"]) {
    cell.labelFlag.text = @"slider";
}else if([strCellId isEqualToString:@"cellSegmented"]){
    cell.labelFlag.text = @"segmented";
}else{
    cell.labelFlag.text = @"switch";
}
return cell;
}

![image](/images/DynamicPrototypesTable/iOS Simulator Screen shot Feb 12, 2014, 5.46.26 PM.png)

工程地址