【发布时间】:2012-03-23 13:31:04
【问题描述】:
我正在使用带有 UITableViewController 和 UITableViewCell 子类的 ios5 故事板。我不想在情节提要设计器中为视图设计单元格的视觉元素,因为我想使用 UITableViewCell 的可重用子类(特别是TDBadgedCell)。
我已经在故事板设计器中设置了我的单元格标识符,并且只要我没有设置任何 TDBadgedCell 独有的属性,所有行都会正确加载到 UITableView 中。如果我设置了 TDBadgedCell 独有的 badgeString 属性,则会出现异常。我缩小范围,dequeueReusableCellWithIdentifier: 没有返回 TDBadgedCell 类型的单元格。
我只是在使用 UITableViewController 时遇到了这个问题。我有一个带有嵌入式 UITableView 的 UIViewController 以相同的方式设置,这不是问题。有什么想法吗?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *CellIdentifier = @"PhoneNumberCell";
TDBadgedCell *cell = (TDBadgedCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if ([cell isKindOfClass:[TDBadgedCell class]])
{
NSLog(@"It is TDBadgedCell");
}
else
NSLog(@"It is NOT TDBadgedCell");
【问题讨论】:
-
你是否也在故事板设计器中将“自定义类”更改为 TDBadgedCell?
-
Prototype Cells in a nib instead of a storyboard 的可能重复项 - 唯一可能,我不确定您是否有此单元格的单独 xib。
-
6 月 1 日 - 就是这样!谢谢!不过,我不确定如何将您的答案标记为答案。
标签: iphone ios5 uitableview storyboard