2012-09-11 3 views
0

내 TableViewController에서 사용자 정의 셀을 사용하고 있습니다. 나는 회사에 관한 몇 가지 데이터를 보여주고있다. 회사 제목은 기본적으로 파란색으로 표시되어 있으며 회사에 유효한 URL이 없는지 확인하여 검정색으로 칠할 수 있습니다. 물론 회사에 유효한 URL이없는 경우 오프닝 회사 웹 사이트를 금지하는 논리를 추가했습니다.URL 검사가 제대로 작동하지 않습니다.

그러나이 테이블보기가 표시 될 때마다 제목이 검정으로 칠해진 유효한 URL이있는 회사가 여러 개 있습니다.

그래서 사파리에서 제목과 여는 URL을 채색하는 데 같은 논리를 사용하고 있지만 색상이 제대로 작동하지 않으며 사파리에서 열리지 않습니다.

어떤 아이디어가 잘못 되었나요?

여기 내 cellForRowAtIndexPath 기능

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

    ResultsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    // Configure the cell... 
    Data *theData = [Data getInstance]; 
    Company *theCompany = [theData.results objectAtIndex:indexPath.row]; 

    cell.lblTitle.text = theCompany.DisplayName; 

    cell.lblDescription.text = theCompany.Description; 
    cell.lblAddressPt1.text = theCompany.AddressPt1; 
    cell.lblAddressPt2.text = theCompany.AddressPt2; 
    cell.lblPhone.text = theCompany.Phone; 
    cell.lblEmail.text = theCompany.Email; 

    cell.lblDescription.adjustsFontSizeToFitWidth = false; 
    cell.lblDescription.lineBreakMode = UILineBreakModeWordWrap; 
    cell.lblDescription.numberOfLines = 0; 
    [cell.lblDescription sizeToFit]; 

    NSURL *candidateURL = [NSURL URLWithString:theCompany.Url]; 
    NSLog(@"%@", candidateURL); 
    if (!(candidateURL && candidateURL.scheme && candidateURL.host)) { 
     cell.lblTitle.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; 
    } 

    return cell; 
} 

그리고 이것은 당신이 블랙 레이블이있는 셀을 큐에서 수도로, 명시 적으로 항상 cell.lblTitle.textColor을 설정해야 didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    Company *company = [[Data getInstance].results objectAtIndex:indexPath.row]; 

    NSURL *candidateURL = [NSURL URLWithString:company.Url]; 
    if (candidateURL && candidateURL.scheme && candidateURL.host) { 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:company.Url]]; 
    } 
} 
+1

'candidateURL 속성 무엇인가 유효성을 테스트하는 값은 무엇입니까? 즉, 이것이 디스플레이 문제 또는 논리 문제입니까? – FluffulousChimp

답변

4

입니다. 그래서 다른 절을 추가하고 당신은 항상 어떤 값으로 cell.lblTitle.textColor을 설정하고 있는지 확인하십시오 : 당신이 cell.lblTitle.textColor = ...`에 중단 점을 넣으면

if (!(candidateURL && candidateURL.scheme && candidateURL.host)) { 
    cell.lblTitle.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; 
else 
    cell.lblTitle.textColor = [UIColor colorWithRed:0 green:0 blue:1 alpha:1]; 
+0

그건 속임수 였어. 고맙습니다. 투표를하고 대답을 수락하십시오. 이 일이 왜 일어 났는지 설명해 주시겠습니까? cellForRowAtIndexPath의 현재 셀이 스토리 보드에서 색상을 상속받지 않는 이유는 무엇입니까? – Eedoh

+1

재사용 가능한 단일 셀 이름 "StandardSearchResultCell"만 사용하고 있으므로 테이블을 스크롤 할 때 파란색 또는 검은 색 레이블이있는 재활용 셀을 확보하게됩니다. 또 다른 재사용 가능한 셀 이름을 사용하여이 문제를 해결할 수 있습니다. – CSmith

+0

오, 설명을 위해 thx. 이 tableview 다른 문제가 있습니다. 당신에 대한 설명이 끝난 후에도 같은 문제에 어떻게 든 관련 될 수 있다고 생각합니다. 가능한 경우이 주제를 확인할 수 있습니까? http://stackoverflow.com/questions/12379401/multiline-label-in-custom-cell-overlaps-the-next-cell-when-scrolling-fast – Eedoh

관련 문제