- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已经实现了自定义表格单元格,当表格进入 cellForRowAtIndexPath 时收到运行时错误(“无法识别的选择器发送到实例”)。尝试实例化自定义单元格时发生错误。我之前已经成功地做到了这一点,但现在错误不会消失。我有一个 prtotype 单元格,它的自定义类属性设置为自定义单元格 UITableViewCell 子类。这是自定义单元格:
#import "FavoriteCell.h"
@implementation FavoriteCell
@synthesize lblGaugeID, lblMainTitle, bgImage;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
bgImage = [UIImage imageNamed:@"tableCellBG.png"];
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UIColor *transparentBG = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
UIColor *foregroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
//UIColor *shadowColot = [UIColor colorWithWhite:0.75 alpha:1.0];
CGSize size = self.contentView.frame.size;
self.backgroundView = [[UIImageView alloc] initWithImage:bgImage];
self.lblMainTitle = [[UILabel alloc] initWithFrame:CGRectMake(8.0, 0.5, size.width-16, size.height-40)];
[self.lblMainTitle setFont:[UIFont systemFontOfSize:12.0]];
[self.lblMainTitle setTextAlignment:NSTextAlignmentLeft];
[self.lblMainTitle setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[self.lblMainTitle setBackgroundColor:transparentBG];
self.lblGaugeID = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 31.0, size.width-16, size.height-40)];
[self.lblGaugeID setFont:[UIFont boldSystemFontOfSize:15.0]];
[self.lblGaugeID setTextAlignment:NSTextAlignmentLeft];
[self.lblGaugeID setTextColor:foregroundColor];
[self.lblGaugeID setShadowOffset:CGSizeMake(0.2 , 0.2)];
[self.lblGaugeID setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[self.lblGaugeID setBackgroundColor:transparentBG];
[self.contentView addSubview:lblGaugeID];
[self.contentView addSubview:lblMainTitle];
}
return self;
}
@end
这是实例化的地方(摘 self 的 View Controller 类):
-(FavoriteCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"favoriteCell";
FavoriteCell *cell = (FavoriteCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; //error
if(cell == nil){
cell = [[FavoriteCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSString *siteName = [faveKeys objectAtIndex:indexPath.row];
[cell.lblMainTitle setText:siteName];
[cell.lblGaugeID setText:[allFavorites objectForKey:siteName]];
return cell;
}
这是完整的错误信息:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString instantiateWithOwner:options:]: unrecognized selector sent to instance 0x24bb0'
任何人都可以就检查的内容提供一些建议吗?谢谢!薇薇安
最佳答案
使用 - (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier
是一个如果您在单独的 NIB 文件中定义自定义单元格的好主意
.问题是您传递了 NSString 而不是 UINib 对象。
改为这样做:
[self.tblFavorites registerNib:[UINib nibWithNibName:@"favoriteCellView"bundle:nil] forCellReuseIdentifier:@"favoriteCell"];
但是因为您使用的是原型(prototype)单元而不是单独的 NIB,所以根本没有必要这样做。相反,您只需要确保正确设置原型(prototype)单元格的重用标识符(在本例中为“favoriteCell”)。
关于ios - "Unrecognized selector sent to instance"使用自定义表格单元格时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16637434/
我想知道这两者之间有什么不同 .myClass/DomElement .myotherclassinsidethatelement 和 .myClass/DomElement > .myothercl
使用 jQuery on() 版本 1.7。我通常这样绑定(bind)我的事件: $(".foo").on("click", function() { console.log("foo cli
我想找到与选择器匹配的所有元素,但如果它已经包含在匹配元素中则不查找。 $('#container').find('.child').not('.child .child'); 请注意,.child
我有一个看起来像这样的无序列表,但更广泛: Parent Category 2 Parent Category 2 Parent Category 3
这个问题在这里已经有了答案: CSS negation pseudo-class :not() for parent/ancestor elements (2 个答案) 关闭 4 年前。
我希望使用 CSS :not() 来定位 before 选择器。这可能吗? 示例: https://jsfiddle.net/uuq62b8d/ a.button:before { content
这有什么区别: $.each($('#myTable input[name="deleteItem[]"]:checked').do_something()); 还有这个: $('#myTable i
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我正在使用 UL LI 列表和 jQuery 创建一棵树。我使用了 jQuery 选择器 jQuery(li:has(ul)) 查找所有具有子节点的列表节点,然后向其添加单击事件。 jQuery(li
我真的不知道如何命名这两种方法,所以请原谅我这样调用它们。 字符串选择器 $("#myList li").eq(3); 函数选择器 $("#myList li:eq(3)"); 据我所知,他们都做同样
我有以下代码: .. 我正在使用以下 CSS 来排除具有“main-l tbl”类的表: table:not(.main-l .views-table) { .. } 我注
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: What is the difference between $ and jQuery 我注意到使用“jQuery(
我有许多 css 选择器和许多选择器异常,所以我使用 :not 将它们排除在外... 示例(只是一些我不需要的选择器): [class*="-dashboard-"]:not([class$="-bi
CADisplayLink 有这个方法是有道理的,但我很好奇为什么 UIScreen 也会有它。 最佳答案 文档说屏幕提供的显示链接与该屏幕相关联。但是,查看官方文档,与任何屏幕都没有明显的关系;显示
我在这里阅读了关于 toArray() 的文档,并在控制台中对其进行了测试。我找不到在选择器上调用 toArray() 和调用选择器本身之间的区别。 两种方式都得到了完全相同的结果,这是一个与选择器匹
我有一个问题,为什么这两个代码片段不同。 $('#ctl00_DDMenu1_HyperLink1') //jQuery(a#ctl00_DDMenu1_HyperLink1 Default.asp
我想通过以下方式模拟我可以在 jQuery 中实现的目标$('.someClass:not(.hidden)') 我试过下面的代码。 $crawler->filter('someClass:not(.
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我想通过以下方式模拟我可以在 jQuery 中实现的目标$('.someClass:not(.hidden)') 我试过下面的代码。 $crawler->filter('someClass:not(.
我想根据 Iterator::next 中当前枚举变体的某些属性更改枚举变体。我有两次尝试,都没有编译: enum Test { A(Vec), B, } impl Iterator
我是一名优秀的程序员,十分优秀!