views:

36

answers:

1

I've written some code for a button action. First I'm creating a button "UI", and its onAction should call ButtonListener in @selector in addTarget. But it doesn't seem to be entering the @selector(UIButtonListener) method.

Here's my 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;
  }
 }
}
A: 

Try

[UIButton_G_obj addTarget:self action:@selector(UIButtonListener:) forControlEvents:UIControlEventTouchUpInside];

-(void)UIButtonListener:(id)sender
Jordan