UIButton addTarget不适用于iOS7,但适用于IOS6

时间:2013-12-02 02:28:01

标签: ios ios7 uibutton uipickerview

显然,此代码适用于iOS 6.顺便说一句,它在iOS 7中存在问题。

我将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;
}

1 个答案:

答案 0 :(得分:1)

您无法在选择器视图行上放置按钮。所以我在UIPickerView上面添加了一个工具栏,并在其上添加了一个条形按钮项。我使用行号通过选择器

执行所需的功能
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
     ....
     //get the row number & Perform desired functionality
     ....
}

您将获得行号并使用它来执行所需的功能。