1
我可以实现这一目标吗?如何为不同的UITableView部分使用不同的表格视图单元格类别
if (indexpath.section == 0) {
// Use Class 1
} else if (indexpath.section == 1) {
// Use Class 2
}
我试过,但没有工作
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
OneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"One" forIndexPath:indexPath];
if(cell == nil){
cell = [[OneTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"One"];
}
cell.oneLabel.text = @"HAHAHA";
return cell;
}else{
TwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Two" forIndexPath:indexPath];
if(cell == nil){
cell = [[TwoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Two"];
}
cell.twoLabel.text = @"HEHEHE";
return cell;
}
}
解释什么是不工作。 – Wain 2015-02-08 14:10:22
您是否使用正确的标识符在“UITableView”中注册了每个类? – tbaranes 2015-02-08 14:19:51