1

我有一个非常简单的子类UIViewController

@interface RoastChickenViewController : UIViewController {
    IBOutlet UISlider *weightSlider;    
}

@property (nonatomic,retain) UILabel *cookingTimeLabel;
- (void) weightValueHasChanged:(id)sender;
@end

我的 xib 文件设置为具有RoastChickenViewController文件的所有者类型,并且weightSlider已连接,并且“valueChanged”操作已连接到weightValuHasChanged:.

问题是一旦我触摸滑块(模拟器或设备),我就会得到:

2010-08-21 20:26:07.688 CookIt1[26682:207] -[NSCFString weightValueHasChanged:]: unrecognized selector sent to instance 0x59215e0
2010-08-21 20:26:07.690 CookIt1[26682:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString weightValueHasChanged:]: unrecognized selector sent to instance 0x59215e0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x02395919 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x024e35de objc_exception_throw + 47
    2   CoreFoundation                      0x0239742b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x02307116 ___forwarding___ + 966
    4   CoreFoundation                      0x02306cd2 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x002b9e14 -[UIApplication sendAction:to:from:forEvent:] + 119
    6   UIKit                               0x003436c8 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x00345b4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    8   UIKit                               0x003c23ac -[UISlider beginTrackingWithTouch:withEvent:] + 731

一点点历史,我实际上是使用直接继承 UIView 来完成这项工作的。我已经设法在从 UIView 转换为 UIViewController 时打破它,我想这是实现这种简单行为的更自然的方式。

有没有我可以申请的清单,因为显然我缺少一些东西。

4

2 回答 2

1

这种错误(当接收到消息的对象与预期的类型完全不同时)通常发生在接收者对象由于某种原因被释放并且它在内存中的地址现在被其他对象占用时。

因此,您需要检查控制器的内存管理是否一切正确。

于 2010-08-21T20:13:04.867 回答
1

好像您在 NSCFString 上调用 weightValueHasChanged。这几乎肯定不是你想要的!要么您在 IB 中的连接中断,要么您将 weightValueHasChanged 显式发送到 NSCFString 的实例。

于 2010-08-21T19:34:40.573 回答