そのため、アプリで発生する非常に奇妙なクラッシュに困惑しています。
背景: UIButtonをオーバーライドするクラスCustomButtonがあります。簡単に言えば、インターフェイスは次のようになります。
@interface CustomButton : UIButton
@property (nonatomic, getter = isLoading) BOOL loading;
@end
実装:
@implementation CustomButton
@synthesize loading = loading_;
- (id)init {
if ((self = [UIButton buttonWithType:UIButtonTypeCustom])) {
[self setTitle:NSLocalizedString(@"My Button", nil) forState:UIControlStateNormal];
[[self titleLabel] setShadowColor:[UIColor blackColor]];
[[self titleLabel] setShadowOffset:CGSizeMake(0, -1)];
[self setContentEdgeInsets:UIEdgeInsetsMake(0, 77, 0, 30)];
UIImage *backgroundImage = [[UIImage imageNamed:@"back.png"] stretchableImageWithLeftCapWidth:77 topCapHeight:0];
UIImage *highlightedBackgroundImage = [[UIImage imageNamed:@"back_highlighted.png"] stretchableImageWithLeftCapWidth:77 topCapHeight:0];
[self setBackgroundImage:backgroundImage forState:UIControlStateNormal];
[self setBackgroundImage:highlightedBackgroundImage forState:UIControlStateHighlighted];
[self sizeToFit];
}
return self;
}
- (void)setLoading:(BOOL)loading {
if (loading_ != loading) {
// Do fancy things
}
}
@end
問題: クラスでボタンを使用しようとしているので、プロパティなどがあります:
...
@property(nonatomic, strong) CustomButton *customButton;
...
@syntesize customButton = customButton_;
...
- (void)aMethod {
self.customButton.loading = YES;
}
...
もちろん、ボタンは初期化されています。次に、ステートメントself.bookButton.loading = YESを実行すると、このエラーが発生します
2012-08-28 12:54:25.091 MyApp[9465:15803] -[UIAccessibilityBundle
setLoading:]: unrecognized selector sent to instance 0x8650cc0
2012-08-28 12:54:25.091 MyApp[9465:15803] *** Terminating app due
to uncaught exception 'NSInvalidArgumentException', reason:
'-[UIAccessibilityBundle setLoading:]: unrecognized selector sent to
instance 0x8650cc0'
*** First throw call stack: (0x1ead022 0x203ecd6 0x1eaecbd 0x1e13ed0 0x1e13cb2 0x26bf5 0x257ce 0xfa938f 0xfa96a4 0xfa99a7 0xfb8aea
0x11600be 0x11603c7 0x1160436 0xf10e49 0xf10f34 0xc5bcaac 0xe04b54
0x272e509 0x1de4803 0x1de3d84 0x1de3c9b 0x27887d8 0x278888a 0xee0626
0x14cce 0x27b5 0x1) terminate called throwing an exception
正直なところ、何を探すべきかわかりません。それは本当に本当にばかげたものか、本当に卑劣なもののどちらかです。もちろん、すでに google/stackoverflow で検索していますが、答えを得ることができませんでした。私の知る限り、通常、そのエラーは、オブジェクトが送信されたメッセージを「理解」していないときに発生しますが、これは当てはまりません。コンパイラから警告すら出ません。
私が何を探すことができるかについてのアイデアがあれば、または詳細が必要な場合は、お知らせください。
編集:ARCを使用していることを指定するのを忘れました。
更新: 以下の回答で、Phillip Millsは、時期尚早のメモリ リリースの問題である可能性があると述べました。良い点ですが、Instrument はゾンビを見つけられませんでした。さらに、クラッシュしたステートメントの直前にログを配置しました。ここでは、CustomButton オブジェクトに関する情報と、タイトルなどの UIButton に関連するいくつかの情報を出力しようとしています。すべてが正常に見えます。タイトルは私が設定したものであり、フレームはそこにあります...そのため、オブジェクト (実際の UIButton) が存在し、それも期待されるものだと思います。唯一のことは、すべてを台無しにする「読み込み」プロパティです。
解決策: initメソッドが問題の原因でした。ボタンのサブクラスのインスタンスを初期化する代わりに、UIButton のインスタンスを初期化していました。そのため、結果として、「読み込み中」のプロパティが見つかりませんでした。initをinitWithFrameに置き換え、標準の手順を使用してイニシャライザをオーバーライドすると、すべてがうまく機能します。それでも謎ですが、 UIButtonではなくUIAccessibilityBundleをエラーの原因として取得した理由。