2009-04-19 3 views
2

스크롤이 활성화되어 있으면 UITableView가 스크롤하는 UIView를 얻으려고 노력하고 있습니다. 일반적으로 배경은 흰색이고 UITableView를 경계 밖으로 밀어 내면 배경이 보입니다. 이 배경을 blackColor의 UIColor로 설정하려고합니다. 나는 적절한 태그를 찾을 수없는 것 같습니다. 내 UIViewController에서 다음 코드를 시도했습니다 :UITableView가 스크롤하는 UIView 찾기

- (void)loadView 
{ 
    [super loadView]; 
    UITableView *aTableView = 
     [[[UITableView alloc] 
      initWithFrame:self.view.bounds 
      style:UITableViewStylePlain] autorelease]; 

    [aTableView setScrollEnabled:YES]; 
    [self.view setBackgroundColor:[UIColor blackColor]]; 
    [self.view addSubview:aTableView]; 
    self.tableView = aTableView; 
} 

색상은 여전히 ​​흰색으로 유지됩니다. 잘못된 UIView를 치고있는 것 같습니다.

아이디어가 있으십니까? 감사.

답변

0

해결책이 없지만 제안 사항이 있습니다. UITableView의 backgroundColor를 투명하게 만들고 superview의 색상을 흰색으로 설정하려고 했습니까?

+0

안녕하세요, Roger, blackColor가 내 UITableView에 스며 들지 않게하고 싶습니다. 나는 그것의 정상적인 스타일링을 원한다. 테이블이 그 범위 밖으로 스크롤 될 때 배경을보고 싶습니다. – Coocoo4Cocoa

0

나는 당신이 원하는 것을 얻을 수 있었지만, 나에게 (아마도 라이브러리에 버그가 있음) 해결 방법처럼 보였다.

먼저 UITableView에서 backgroundColor 속성을 black으로 설정해야합니다. 새있는 UITableViewCell을 만들 때

그렇다면, 당신은 다음과 같이 (이 코드는 jQuery과의 데이터 소스에 간다) 할 필요가 : 당신은 흰색에있는 contentView의 배경색을 설정해야

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

    // Try to retrieve from the table view a now-unused cell with the given identifier 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

    // If no cell is available, create a new one using the given identifier 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; 
    } 
    cell.contentView.backgroundColor = [UIColor whiteColor]; 

    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 60, 20)] autorelease]; 
    label.text = @"test"; 
    label.textColor = [UIColor blackColor]; 
    [cell.contentView addSubview:label]; 
    cell.textColor = [UIColor blackColor]; 

    return cell; 
} 

을하지만, 그렇게하면 셀의 텍스트가 나타나지 않으므로 내용보기에 UILabel을 추가하고 텍스트를 직접 작성해야합니다.

그냥 배경색을 변경하는 것이 과도한 것 같지만 UITableViewCell에 포함 된 UITableView와는 다른 배경색을 설정하지 못하게하는 버그가있을 수 있습니다.

0

음 .. cellForRowAtIndexPath 메서드에서 셀의 배경색을 설정하는 비슷한 문제에서 실행됩니다. 해결 방법은 콜백 메서드 willDisplayCell에서 배경색을 설정하는 것이 었습니다.

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    cell.backgroundColor = (indexPath.row % 2 == 0) ? DARK_BACKGROUND : LIGHT_BACKGROUND; 
}