我已经为UITableViewCell
创建了一个自定义UITableView
,方法是将标签和imageView
从我的原型单元格拖放到我称之为QuizInfoCell的自定义单元格。
对于我在其中创建原型单元格的特定TableView
工作正常,但我不能让QuizInfoCell
为其他任何TableView.
工作我怎样才能实现?< / p>
这是我在创建Prototype Cell的TableView
中使用的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
QuizInfoCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"QuizInfoCell" forIndexPath:indexPath];
if (cell == nil){
cell = [[QuizInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"QuizInfoCell"];
}
cell.name.text = [title objectAtIndex:indexPath.row];
cell.author.text = [author objectAtIndex:indexPath.row];
cell.time.text = [[ValueHandler alloc] getDateString:[timeStamp objectAtIndex:indexPath.row]];
cell.plays.text = [@"Plays: " stringByAppendingString:[NSString stringWithFormat:@"%@", [plays objectAtIndex:indexPath.row ]]];
cell.ratingUps.text = [NSString stringWithFormat:@"%@", [ratingUps objectAtIndex:indexPath.row]];
cell.ratingDowns.text = [NSString stringWithFormat:@"%@", [ratingDowns objectAtIndex:indexPath.row]];
cell.qid.text = [NSString stringWithFormat:@"%@", [qid objectAtIndex:indexPath.row]];
return cell;
}
答案 0 :(得分:0)
我建议您将QuizInfoCell
创建为新的XIB文件。
User Interface
子菜单。View
并将其命名为QuizInfoCell
在新的XIB中删除现有的View元素,然后拖放新的Table View Cell
。
通过拖放标签和imageView
,以与之前相同的方式重新创建自定义UITableViewCell
最后给新的Cell一个名为QuizInfoCell
的标识符,如下所示:
然后,您可以使用代码加载新的自定义UITableViewCell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
QuizInfoCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"QuizInfoCell" forIndexPath:indexPath];
if (cell == nil){
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"QuizInfoCell" owner:self options:nil];
cell = [nibContents objectAtIndex:0];
}
cell.name.text = [title objectAtIndex:indexPath.row];
cell.author.text = [author objectAtIndex:indexPath.row];
cell.time.text = [[ValueHandler alloc] getDateString:[timeStamp objectAtIndex:indexPath.row]];
cell.plays.text = [@"Plays: " stringByAppendingString:[NSString stringWithFormat:@"%@", [plays objectAtIndex:indexPath.row ]]];
cell.ratingUps.text = [NSString stringWithFormat:@"%@", [ratingUps objectAtIndex:indexPath.row]];
cell.ratingDowns.text = [NSString stringWithFormat:@"%@", [ratingDowns objectAtIndex:indexPath.row]];
cell.qid.text = [NSString stringWithFormat:@"%@", [qid objectAtIndex:indexPath.row]];
return cell;
}