У меня есть UIButton, сделанный программно, и я хочу добавить цель и действие для этой кнопки. У меня есть метод использования addTarget: action: forControlEvents:
UIButton addTarget метод не может использоваться в IOS 4.2
в IOS 4.1 обнаружен этот метод, но в 4.2 это не так, вот мой код
UIButton *moreButton = [[[UIButton alloc] init] autorelease];
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];
}
и это метод действия:
- (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];
}
любое тело знает, что здесь не так?
yes..it должен работать, а неправильный код - я использовал UIButton как глобальную переменную, но я ее не выделял. Я действительно забыл об этом. Теперь я решил проблему, и я изменил свой код выше. Спасибо за ответ Гопал –