2011-10-13 1 views
0

버튼을 응답하지 않습니다 viewForRow에서 UIPickerView있는 UIButton은 viewForRow에 응답하지 않습니다

UIView * rowView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)] autorelease]; 

UIButton* deleteButton = [[[UIButton alloc]init]autorelease]; 
deleteButton.frame = CGRectMake(200, 10, 20,20); 
[deleteButton setImage:[UIImage imageNamed:@"IconTrash.png"] forState: UIControlStateNormal]; 
[deleteButton addTarget: self action:@selector(removeCellAtIndexPath:) forControlEvents: UIControlEventTouchUpInside]; 

UILabel *labelText = [[UILabel alloc]init]; 
labelText.text = [NSString stringWithFormat:@"%@",[[localFlagNotes objectAtIndex:row] value]]; 
labelText.font = [UIFont fontWithName:@"Arial" size: 24]; 
labelText.frame = CGRectMake(0, 10, 200, 28); 
labelText.backgroundColor = [UIColor clearColor]; 

[rowView addSubview:labelText]; 
[rowView addSubview:deleteButton]; 
[labelText release]; 
return rowView; 

removeCellAtIndexPath

이 버튼을 누르면 이후에 호출하지 않습니다. 누구는 왜 어떤 생각을 가지고 있습니까?

버튼을 눌러도 셀이 활성화되지 않는 것 같습니다.

답변

0

내가 방법을 찾아 당신의 rowView의 프레임으로 라벨과 deleteButton의 프레임을 조정 초과 . 단지

- (UIView*)pickerView:(UIPickerView *)pickersView viewForRow:(NSInteger)row 
      forComponent:(NSInteger)component reusingView:(UIView *)view 
    { 
      PickerCustomView * rowView = [[PickerCustomView alloc]initWithFrame:CGRectMake(5, 0, 310, 50) withText:[[localFlagNotes objectAtIndex:row] value]] ; 
      rowView.delegate = self; 
      return rowView; 
    } 

에서 버튼을 사용자 정의보기 만들기이

- (id)initWithFrame:(CGRect)frame withText:(NSString*)text 
{ 
    self = [super initWithFrame:frame]; 
    if (self) 
{ 
    deleteButton = [[UIButton alloc]init]; 

    [deleteButton setImage:[UIImage imageNamed:@"IconTrash"] forState: UIControlStateNormal]; 
    [deleteButton addTarget:self action:@selector(deleteButtonAction:) forControlEvents:UIControlEventTouchUpInside]; 
    deleteButton.frame = CGRectMake(250, 10, 35,35); 

    textLabel = [[UILabel alloc]init]; 
    originText = text; 
    NSString *trimmed = [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 
    textLabel.text = trimmed; 
    textLabel.font = [UIFont fontWithName:@"Arial" size: 24]; 
    textLabel.frame = CGRectMake(20, 10, 230, 28); 
    textLabel.backgroundColor = [UIColor clearColor]; 

    [self addSubview:textLabel]; 
    [self addSubview:deleteButton];  

} 
return self; 

}

및 사용과 마찬가지로

:

-(void)deleteButtonAction:(id)sender 
{ 
    [delegate removeCellAtIndexPath:originText]; 
} 

또는 :

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:touch.view]; 

    if ((location.x > 10 && location.x < 38) && (location.y > 240 && location.y < 265) ) 
    { 
     [self deleteButtonAction:nil]; 
    } 
} 
+0

나를 위해 작동하지 않습니다 –

0

귀하의 deleteButtonUr 버튼의 프레임 (폭)를 rowView의이 같은으로 뷰의 프레임을 증가 frame.so

UIView * rowView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 44)] autorelease]; 

달리

+0

TNX 내 실수)) 지금은 버튼을 누를 수 있습니다 ...하지만 선택은 유 – UnRewa

+0

전화 나던 - (무효) removeCellAtIndexPath : 보낸 사람 를 (ID) {// UR 코드 } –

+0

이 같이 할 UR 선택 정의 방법 –