iOS 7中的UIPickerView按钮选择器问题 [英] UIPickerView button selector issue in iOS 7
本文介绍了iOS 7中的UIPickerView按钮选择器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
仅在iOS 7上有一个奇怪的UIPickerView问题
Having a weird issue of UIPickerView only on iOS 7
我有一个包含3行的UIPickerView。每行都有一个按钮,其选择器已定义,但它永远不会响应按钮点击。
I have a UIPickerView which contains 3 rows. Each row has a button whose selector is defined, but it never respond on button tap.
这是我的代码。
- (UIView *)pickerView:(UIPickerView *)pickerView
viewForRow:(NSInteger)row
forComponent:(NSInteger)component
reusingView:(UIView *)view {
NSLog(@"row %d", row);
if(view == nil) {
view = [[[UIView alloc] init] autorelease];
}
[view setFrame:CGRectMake(0, 0, 320, 44)];
UIButton *manageButton = (UIButton *)[view viewWithTag:TAG_MANAGE + row];
UILabel *descTypeLabel = (UILabel *) [view viewWithTag:TAG_DESCTYPE_LABEL + row];
if(manageButton == nil && row != 0) {
CGRect frame = CGRectMake(210, 7, 90, 30);
manageButton = [UIButton buttonWithType:UIButtonTypeCustom];
manageButton.frame = frame;
[manageButton setTitle:@"Manage" forState:UIControlStateNormal];
[manageButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[manageButton setBackgroundImage:[[UIImage imageNamed:@"blackButton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(8, 8, 8, 8)] forState:UIControlStateNormal];
manageButton.tag = TAG_MANAGE + row;
[view addSubview:manageButton];
}
if(descTypeLabel == Nil) {
descTypeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 190, 44)];
descTypeLabel.backgroundColor = [UIColor clearColor];
descTypeLabel.tag = TAG_DESCTYPE_LABEL + row;
[descTypeLabel setText:[descTypes objectAtIndex:row]];
[view addSubview:descTypeLabel];
[descTypeLabel release];
}
//[manageButton addTarget:self action:@selector(managePressed:) forControlEvents:UIControlEventTouchUpInside];
[manageButton addTarget:self action:@selector(manageButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
return view;
}
-(void) manageButtonPressed : (UIButton *) sender {
//Not Called
}
推荐答案
您不能在选择器视图单元格上使用按钮。我使用了工具栏并在其上添加了一个条形按钮项。通过这个
You can't use button on picker view cell. I have used toolbar and added a bar button item on it. By this
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
您将获得行号并使用它来执行所需的功能。
you will get the row number and use that to perform desired functionality.
这篇关于iOS 7中的UIPickerView按钮选择器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文