Warum ist der Steuerfluss nicht eintritt @selector (Methodenname)?
Frage
Ich habe einige Code für eine Schaltfläche Aktion geschrieben. Zuerst bin ich Erstellen einer Schaltfläche "UI"
und seine onAction
in ButtonListener
in @selector
nennen addTarget
sollte. Aber es scheint nicht die @selector(UIButtonListener)
Methode zu gelangen.
Hier ist mein Code:
UIButton_G_obj = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
UIButton_G_obj.frame = CGRectMake(100,30,100,50);
[UIButton_G_obj setTitle:@"UI" forState:UIControlStateNormal];
UIButton_G_obj.backgroundColor = [UIColor clearColor];
[subMainView_obj addSubview:UIButton_G_obj];
[UIButton_G_obj addTarget:self action:@selector(UIButtonListener) forControlEvents:UIControlEventTouchUpInside];
-(void)UIButtonListener
{
NSArray *array = [subUiCtxt_G_obj getMList];
int count ;
for (NSString *string in array)
{
count ++;
}
int w=100,x=30,y=100,z=50;
//set view property ov controller to the newly created view
if(count>0)
{
for(NSString *st in array)
{
// create Button's for modules in array (UIButtonTypeRoundedRect)
UIButton_G_obj = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
UIButton_G_obj.frame = CGRectMake(w,x,y,z);
[UIButton_G_obj setTitle:st forState:UIControlStateNormal];
UIButton_G_obj.backgroundColor = [UIColor clearColor];
[mainView_G_obj addSubview:UIButton_G_obj];
x=+70;
}
}
}
Lösung
Versuchen
[UIButton_G_obj addTarget:self action:@selector(UIButtonListener:) forControlEvents:UIControlEventTouchUpInside];
-(void)UIButtonListener:(id)sender
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow