我有一个用于Rich Text编辑的iPad应用程序......
它包含UITableView
。我创建的EditorView
继承了UITableViewCell
。
在EditorView
中,我添加了UITextView
或ImageView
或TableView
。
应用程序有时会崩溃并显示以下消息;
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ImageView layout]: unrecognised selector sent to instance 0x1886f650'
First throw call stack:
ARRAY : (
0 CoreFoundation 0x30374e9b <redacted> + 154
1 libobjc.A.dylib 0x3ab296c7 objc_exception_throw + 38
2 CoreFoundation 0x303787b7 <redacted> + 202
3 CoreFoundation 0x303770af <redacted> + 706
4 CoreFoundation 0x302c5dc8 _CF_forwarding_prep_0 + 24
5 ZohoWriter 0x000a916f -[EditorView layoutSubviews] + 1642
6 UIKit 0x32af9353 <redacted> + 346
7 QuartzCore 0x3277f943 <redacted> + 142
8 QuartzCore 0x3277b167 <redacted> + 350
9 QuartzCore 0x3277aff9 <redacted> + 16
10 QuartzCore 0x3277aa0d <redacted> + 228
11 QuartzCore 0x3277a81f <redacted> + 314
12 QuartzCore 0x3277454d <redacted> + 56
13 CoreFoundation 0x3033ff69 <redacted> + 20
14 CoreFoundation 0x3033d8f7 <redacted> + 286
15 CoreFoundation 0x3033dc43 <redacted> + 738
16 CoreFoundation 0x302a8471 CFRunLoopRunSpecific + 524
17 CoreFoundation 0x302a8253 CFRunLoopRunInMode + 106
18 GraphicsServices 0x34fbc2eb GSEventRunModal + 138
19 UIKit 0x32b5d845 UIApplicationMain + 1136
20 ZohoWriter 0x0008d271 main + 116
21 libdyld.dylib 0x3b022ab7 <redacted> + 2
)
我的代码是:
EditorView :
@interface EditorView : UITableViewCell
{
NSString *mViewType;
NSDictionary *mMargin;
}
@implementation EditorView
- (id)initWithMargin:(NSDictionary *)margin withViewType:(NSString *)type withIndexPath:(NSArray *)indexPath
{
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EDITOR_VIEW_ID"];
if (self) {
mUtils = [Utilities instance];
mMargin = margin;
_indexPath = indexPath;
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.autoresizingMask = UIViewAutoresizingFlexibleHeight;
mViewType = type;
[self.contentView addSubview:/* Here I'll add either Textview or Imageview or TableView*/];
[self.contentView sizeToFit];
}
return self;
}
- (NSString *)viewType
{
return mViewType;
}
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect bounds = self.contentView.frame;
bounds.origin.x = [[mMargin objectForKey:@"left"] integerValue];
if ([[_indexPath objectAtIndex:0] integerValue] == 1) {
bounds.origin.y = [[mMargin objectForKey:@"top"] integerValue];
bounds.size.height -= bounds.origin.y;
}
bounds.size.width -= bounds.origin.x+[[mMargin objectForKey:@"right"] integerValue];
self.contentView.frame = bounds;
UIView *contentView = [self.subviews objectAtIndex:0];
if ([mUtils is_iOS7]) {
contentView = [contentView.subviews objectAtIndex:0];
}
UIView *subView = [contentView.subviews objectAtIndex:0];
if ([mViewType isEqualToString:VIEW_TYPE_TEXT_VIEW]) {
subView.frame = self.contentView.bounds;
} else if ([mViewType isEqualToString:VIEW_TYPE_TABLE_VIEW]) {
bounds.origin = CGPointZero;
subView.frame = bounds;
[((TableView *)subView).layout invalidateLayout];
}
}
@end
答案 0 :(得分:0)
错误表示您正在调用[ImageView布局],但此类(ImageView)中没有声明布局方法。您必须在ImageView类中声明布局方法,否则必须删除该调用。
答案 1 :(得分:0)
由于您不熟悉iOS开发,我会概括答案。
由于以下两个原因之一,您会看到该特定错误:
进一步详细说明,我们需要看看ImageView - 它似乎是一个自定义类。但在此之前,您可能需要调试并找出ImageView在运行时的值,或者通过分析器运行应用程序并确保没有僵尸。
答案 2 :(得分:0)
具体问题在于这一行:
[((TableView *)subView).layout invalidateLayout];
您将subView
投射到TableView
,但它实际上是ImageView
。我的猜测是mViewType
没有返回你期望的值。