UIButton addTarget method can not use in IOS 4.2

Posted by Risma on Stack Overflow See other posts from Stack Overflow or by Risma
Published on 2010-12-24T04:35:43Z Indexed on 2010/12/24 4:54 UTC
Read the original article Hit count: 208

Filed under:
|
|
|

hi

i have a UIButton made programmatically and i want to add the target and the action for that button. i have use method addTarget: action: forControlEvents:

in IOS 4.1 this method is detected, but in 4.2 it didn't, here is my code

float version = [[[UIDevice currentDevice] systemVersion] floatValue]; 
    if(version <= 4.1){
        moreButton = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(6.3+5*widthSegment, 0.0, widthSegment, heightSegment)];
        [moreButton addTarget:self action:@selector(getPopOverMore:) forControlEvents:UIControlEventTouchUpInside];
    }
    else{
        //version 4.2
        NSLog(@"versi 4.2");
        moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
        moreButton.frame = CGRectMake(6.3+7*widthSegment, 0.0, widthSegment, heightSegment);
        [moreButton addTarget:self action:@selector(getPopOverMore:) forControlEvents:UIControlEventTouchUpInside];
    }

and this is the action method :

- (IBAction)getPopOverMore:(id)sender{

if(moreFileController == nil) {

    moreFileController = [[MoreFilePopController alloc]
                          initWithStyle:UITableViewStylePlain];

    moreFileController.delegate = self;

    moreFilePopOverController = [[UIPopoverController alloc]
                                 initWithContentViewController:moreFileController];
}

CGRect frameMore = CGRectMake(6.3+5*widthSegment, 0.0, widthSegment, heightSegment);


[moreFilePopOverController presentPopoverFromRect:frameMore inView:navBar 
                         permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

}

any body know, what's wrong here??

© Stack Overflow or respective owner

Related posts about ipad

Related posts about ios4