错误 [NSISLinear表达式方向已更改:]:发送到实例的无法识别的选择器



当我改变方向时,我在应用程序中遇到了这个错误,我一生中第一次得到它,我以前从未见过这种类型的错误,

我已经搜索了很多关于此错误的信息,但我没有找到解决这个问题的方法,

在我的应用程序中,我已经编写了用于方向更改的NSNotization。

滚动条.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];
}

经过这么多次尝试,我发现我没有删除观察器,所以我在 dealloc 方法中删除了它。

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

相关内容

最新更新