2013-10-08 1 views
4

여기 내 코드가 있는데 단추 선택기를 처리 할 수 ​​없습니다.PickerView의 버튼이 작동하지 않습니다. iOS 7

- (UIView *)pickerView:(UIPickerView *)pickerView 
     viewForRow:(NSInteger)row 
     forComponent:(NSInteger)component 
     reusingView:(UIView *)view { 

    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); 
     CGRect frame = CGRectMake(0, 7, view.frame.size.width, 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.layer.borderColor = [UIColor greenColor].CGColor; 
     descTypeLabel.layer.borderWidth = 1.0; 
     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]; 

    return view; 
} 

-(void) managePressed:(UIButton *) sender { 

    //This selector is not called on manage button tap! 

} 

답변

0

나는 당신이 pickerView에 추가하기 전에 manageButton에 선택기를 추가한다고 생각합니다. 코드 행하기 전에

[manageButton addTarget:self action:@selector(managePressed:) forControlEvents:UIControlEventTouchUpInside]; 

:
그냥 코드 줄을 이동

[view addSubview:manageButton]; 

도움이 되었기를 바랍니다.

0

해결책을 찾았습니다. 분명히 완료 버튼이있는 도구 모음을 가진 당신의 디자인에 따라 할 것 UIPickerView 세포에 "보이지 않는"완료 버튼을 추가 할 수 있도록 하나의 좋은 방법 바람직하지 될 수있는 모든 사람들의

// Instantiate an UIImagePicker into your class 
@interface myView() { 
    UIPickerView *_picker; 
} 
@end 

// alloc/init the picker of your class and a UITapGestureRecognizer 
- (void)initPicker { 
    _picker = [[UIPickerView alloc] init]; 
    [_picker addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self 
                      action:@selector(dismissPicker)]]; 
} 

// method called when the user taps on the UIPickerView. 
// The normal behaviour is to use the current selected row as the one wanted by the user. 
- (void)dismissPicker { 
    NSInterger selectedRow = [_picker selectedRowInComponent:0]; 
    // and now use the data and dismiss the picker the way you like the most 
} 

; P

관련 문제