简体   繁体   English

UIButton addTarget不适用于iOS7,但可在IOS6中使用

[英]UIButton addTarget doesn't work with iOS7,but works in IOS6

Obviously, this code works in iOS 6. By the way, it has problem in iOS 7. 显然,此代码在iOS 6中有效。顺便说一下,它在iOS 7中有问题。

I add UIButton to every row in a UIPickerView: 我将UIButton添加到UIPickerView中的每一行:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UIButton *btnRow=[UIButton buttonWithType:UIButtonTypeSystem];
    [btnRow addTarget:self action:@selector(touch:) forControlEvents:UIControlEventTouchUpInside];
    btnRow.frame=CGRectMake(0, 0, 320, 30);
    int tag= selfTextField.tag/10000 - 1;
    [btnRow setTitle:[[pickerArray objectAtIndex:tag] objectAtIndex:row] forState:UIControlStateNormal];

    return btnRow;
}

You can't place a button on picker view row. 您不能在选择器视图行上放置按钮。 So i have added a toolbar above UIPickerView and added a bar button item on it. 所以我在UIPickerView上方添加了一个工具栏,并在其上添加了一个条形按钮项。 I use the row number to perform desired functionality through selector 我使用行号通过选择器执行所需的功能

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
     ....
     //get the row number & Perform desired functionality
     ....
}

you will get the row number and use that to perform desired functionality. 您将获得行号,并使用该行号执行所需的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM