2012-08-15 3 views
3

내 개인용 스타일을 내 UITableView에서 구현하려고하는데 구분 기호에 문제가 있습니다. 정상적인보기와 잘 작동하지만 셀을 선택하면 사라집니다. 내 customSelect보기 분리 기호에 추가하려고하지만 그 다음에 구분 기호를 볼 수 없습니다. 선택한 셀에 구분 기호를 어떻게 추가합니까? UITableViewCell 및 구분 기호가 사라짐

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *MyCellIdentifier = @"MyCellIdentifier"; 

    UITableViewCell *cell = [wallMenuTableView dequeueReusableCellWithIdentifier:MyCellIdentifier]; 

    if(cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyCellIdentifier]; 

     MenuItemModel *mItem = [menu.menuPositions objectAtIndex:indexPath.row]; 
     cell.textLabel.text = mItem.displayName; 
     cell.textLabel.textColor = [UIColor colorWithRed:0.70 green:0.70 blue:0.70 alpha:1.0]; 
     cell.textLabel.backgroundColor = [UIColor clearColor]; 
     cell.textLabel.font = [UIFont fontWithName:@"ArialMT" size:16]; 
     cell.textLabel.shadowColor = [UIColor blackColor]; 
     cell.textLabel.shadowOffset = CGSizeMake(0.0, 1.0); 

     customSeparator = [[UIView alloc] initWithFrame:CGRectMake(0, (cell.frame.origin.y), 320, 2)]; 
     customSeparator.backgroundColor=[UIColor blackColor]; 
     [customSeparator.layer setShadowOffset:CGSizeMake(0.0, 0.8)]; 
     [customSeparator.layer setShadowOpacity:0.8]; 
     [customSeparator.layer setShadowRadius:0.8]; 
     [customSeparator.layer setShadowColor:[UIColor grayColor].CGColor]; 
     [cell.contentView addSubview:customSeparator]; 

     customSelect = [[UIView alloc] initWithFrame:CGRectMake(0, (cell.frame.origin.y+2), cell.frame.size.width, cell.frame.size.height)]; 
     //[customSelect addSubview:customSeparator]; 
     customSelect.backgroundColor = [UIColor clearColor]; 
     [cell setSelectedBackgroundView:customSelect]; 

    } 

    return cell; 
} 

그리고 현재의 결과

:

enter image description here

+0

분리 기호 생성 코드를 if (cell == nil) 블록 외부로 이동하십시오. –

+0

@Rickay - 작동하지 않았습니다. – Kuba

답변

7

분리 기호에 대해 간단한 UIView 대신 UIImageView를 사용하십시오. backgroundColor 값 대신 Image 값을 설정하십시오 (중요합니다!). 채우기 위해 scale로 이미지를 늘립니다.

+0

감사합니다 .. 너무 간단합니다 .. :) – Kuba

+0

위대한! 그것은 나를 위해 일했다! –

0

아마 당신의 costumSelect는 셀의있는 contentView을 받고있다. 이전에 이러한 동작을 구현했지만 UITableViewCell을 서브 클래 싱했습니다. 사용자 지정 셀에서 setSelected 메서드를 재정의하려고합니다.

+0

UITableViewCell 서브 클래 싱해야합니까 또는 내 UITableView 하위 클래스해야합니까? – Kuba

+0

UITableViewCell의 하위 클래스입니다. -drawRect 메소드에서보기를 설정할 수 있고 -setSelected에서 셀의 비헤이비어와 인터페이스를 선택되거나 선택되지 않은 상태로 변경할 수 있습니다. http://zcentric.com/2008/08/05/custom-uitableviewcell/ – btype

+0

문제가 해결 되었습니까? – btype

-1

대조보기 구분자 색을 설정하려면 tableView.separatorColor (및 tableView.separatorStyle)를 사용하십시오. 셀에서 구분 기호를 그릴 경우 separatorStyle = UITableViewCellSeparatorStyleNone을 설정하십시오. 또한 selectionStyle을 UITableViewCellSelectionStyleNone으로 설정하면 도움이 될 것입니다.

+0

단순히 색을 바꾸거나 표준 스타일을 변경하고 싶지 않습니다. 내가 말했듯이 - 나는 자신의 구분 기호와 선택 스타일을 만들고 싶다. – Kuba

+0

구분 기호를 직접 그리는 경우 separatorStyle = UITableViewCellSeparatorStyleNone 사용을 고려해야합니다. 또한, selectionStyle을 UITableViewCellSelectionStyleNone으로 설정하면 도움이 될 것입니다. – CSmith

관련 문제