0

UIView カテゴリ内でMTAnimatedLabel クラス ( https://github.com/mturner1721/MTAnimatedLabel ) を使用しようとしています (ここから scalessec の iOS Toast: https://github.com/scalessec/Toast )

おそらく Obj-C 関連の参照を使用する必要があることを理解しています。これが私がそれをやろうとしている方法です:

    MTAnimatedLabel *existingTestLabel = (MTAnimatedLabel *)objc_getAssociatedObject(self, &testLabelKey);
if(existingTestLabel != nil) return;

MTAnimatedLabel *testLabel = [[[MTAnimatedLabel alloc] initWithFrame:testFrame] autorelease];
testLabel.text = [NSString stringWithFormat:@"Test String."];
NSLog(@"testLabel: %@", testLabel.text);
objc_setAssociatedObject(self, &testLabelKey, testLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self addSubview:testLabel];
[testLabel startAnimation];

次の行の EXC_BAD_ACCESS で失敗します。

    MTAnimatedLabel *testLabel = [[[MTAnimatedLabel alloc] initWithFrame:testFrame] autorelease];

私のtestLabelKeyは次のように定義されています:

static char const * const testLabelKey = "testLabel";

私のtestLabelプロパティは、インターフェースで次のように宣言されています。

@property (nonatomic, retain) MTAnimatedLabel *testLabel;

誰かが私が間違っていることを見つけたり、別の方法を提案したりできますか? ありがとう!

4

0 に答える 0