2010-12-09 3 views
1

Я новичок в Objective C. Я создал метод для построения & отображения кнопки Внутри UIView (UIView находится внутри другого вида с именем contentView и contentView быть добавлен как подвид в UIScrollView. Ну проблема в том, что я не могу нажать на сгенерированного кнопку, чтобы вызвать действие IB под названием playAction. может кто-то пожалуйста, помогите мне? СпасибоНе удается запустить IBAction из в UIButton от UIView

- (void) displayCategoryBestSellers 
{ 
    //Structure: ScrollView -> ContentView -> MainView -> ImageView and Button 

    UIView * mainView = [[UIView alloc] initWithFrame:CGRectMake(0,0,160,105)]; 
    mainView.userInteractionEnabled = YES; 

    UIImage * backgroundImage = [UIImage imageNamed:@"blackwhitesquare.png"];   
    UIImageView * uiImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,145,105)]; 
    uiImageView.image = backgroundImage; 
    uiImageView.center = CGPointMake(mainView.frame.size.width /2, mainView.frame.size.height/2); 
    uiImageView.userInteractionEnabled = YES; 

    [mainView addSubview:uiImageView]; 

    UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; 
    playButton.frame = CGRectMake(0,0,100,90); 

    NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://media.theseus.cataloguesolutions.com/images/72by72/324178611_0004_PG_1.jpg"]]; 
    UIImage *myimage = [[UIImage alloc] initWithData:mydata]; 

    [playButton setBackgroundImage:myimage forState:UIControlStateNormal]; 
    playButton.center = CGPointMake(mainView.frame.size.width /2, mainView.frame.size.height/2);   
    [playButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchDown];  
    playButton.userInteractionEnabled = YES; 

    [mainView addSubview:playButton]; 

    [contentView addSubview:mainView]; 

    contentView.userInteractionEnabled = YES; 

    [scrollView addSubview:contentView]; 
    scrollView.delegate = self; 

    scrollView.userInteractionEnabled = YES;   
} 

-(IBAction)playAction: (id)sender 
{ 
    NSLog(@"Button Clicked"); 
} 
+0

ли кнопку поворота синий w Куда вы нажмете на нее? – Brian 2010-12-10 15:54:57

ответ

1

Использование UIControlEventTouchUpInside вместо UIControlEventTouchDown.

+0

Я попробовал ваше предложение, но все тот же вопрос. Пожалуйста, помогите кому-нибудь, потому что мне действительно нужно это работать. – Lilz 2010-12-10 07:35:08

Смежные вопросы