当我改变方向时,我在应用程序中出现此错误,我在生活中第一次得到它,我以前从未见过这种类型的错误,
我已经搜索了很多关于这个错误,但我没有找到解决这个问题,
在我的应用程序中,我已经编写了NSNotification以进行方向更改
Scroller.m
-(id)initWithFrame:(CGRect)frame {
self=[super initWithFrame:frame];
if (self) {
// Initialization code
scrollView=[UIScrollView new];
pageControl=[UIPageControl new];
scrollView.delegate=self;
scrollView.pagingEnabled=YES;
scrollView.showsHorizontalScrollIndicator=NO;
scrollView.showsVerticalScrollIndicator=NO;
scrollView.translatesAutoresizingMaskIntoConstraints=NO;
pageControl.translatesAutoresizingMaskIntoConstraints=NO;
scrollView.backgroundColor=[UIColor clearColor];
pageControl.backgroundColor=[UIColor darkGrayColor];
[pageControl addTarget:self action:@selector(changePage) forControlEvents:UIControlEventValueChanged];
[self addSubview:scrollView];
[self addSubview:pageControl];
self.pageControl.currentPage = 0;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged)
name:UIDeviceOrientationDidChangeNotification
object:nil];
[self setData];
}
return self;
}
-(void)orientationChanged{
[self updateFrame];
}
-(void)updateFrame{
[self layoutIfNeeded];
CGRect mainFrame=scrollView.frame;
CGRect frame;
.
.
.
.
// COdes for Updating Frame
}
但是我收到了这个错误:
-[NSISLinearExpression orientationChanged:]: unrecognized selector sent to instance 0xa9477c0
2014-02-28 09:56:04.919 TKScroller[604:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSISLinearExpression orientationChanged:]: unrecognized selector sent to instance 0xa9477c0'
修改
我在观察者和方法中删除了参数,并且 运行后我遇到了新的错误
[__NSArrayM orientationChanged]: unrecognized selector sent to instance 0xa0845f0
2014-02-28 10:27:40.202 Scroller[810:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM orientationChanged]: unrecognized selector sent to instance 0xa0845f0'
解决
我已经删除了dealloc方法中的观察者
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
答案 0 :(得分:7)
经过这么多次尝试后,我发现我没有删除观察者,所以我在dealloc方法中将其删除了。
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}