【发布时间】:2013-12-01 14:52:49
【问题描述】:
我有一个用于编辑富文本的 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
【问题讨论】:
-
您仔细阅读错误信息了吗?
reason: '-[ImageView layout]: unrecognised selector sent to instance 0x1886f650 -
@Neeku:是的,我做到了。这是什么意思?我是IOS开发的新手。如果您详细说明问题的原因,将会很有帮助。
-
你检查了哪一行崩溃了吗??
-
@hussainShabbir:它在 [super layoutSubviews] 处崩溃
标签: ios objective-c ipad uitableview