2
次のコードがあります.UIButtonを押すと何も呼び出されず、クラッシュしません。UIButtonのaddtarget:タッチした後に呼び出されません!
calloutButton = [[UIView alloc] initWithFrame:CGRectMake(left_width2*2-3, 5, 230, 230)];
UIButton *buttongo= [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
buttongo.frame=CGRectMake(0, -1, 25, 25);
[buttongo addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
[calloutButton addSubview:buttongo];
[label addSubview:calloutButton];
-(IBAction)buttonEvent:(id)sender
{
NSLog(@"Hello...");
}
なぜか分かりますか?
ありがとうございます!
を持っていた
と同じ名前を持つ
を持っていないことを確認してください。私はあなたが意味するものだと思います。 label = [[UIView alloc] initWithFrame:CGRectMake(((left-width2 * 2 + 21)/ 2)-21,19 - ANCHOR_Y、100、CALLOUT_HEIGHT)]; label.backgroundColor = [UIColor brownColor]; 茶色がラベル – saimonx
の背後にある場合は、UILabelのuserInteractionEnabledがYESであるかどうかをテストしてください。また、なぜラベルにボタンを追加するのですか? –
whats left_widthと他の変数、cgrectのすべての正確な値を表示するか、変数の値を伝えます。 –