0

TableViewControllerでは、カスタムセルを使用しています。会社に関するデータを表示しています。会社のタイトルはデフォルトで青になっていますが、会社に有効なURLがないかどうかを確認しているので、黒でペイントできます。もちろん、会社に有効なURLがない場合は、会社のWebサイトを開くことを禁止するロジックを追加しました。

ただし、このテーブルビューが表示されるたびに、タイトルが黒く塗られている有効な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;
}

これは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]];
    }
}
4

1 に答える 1

4

ブラックラベルのセルをデキューする可能性があるため、cell.lblTitle.textColorを常に明示的に設定する必要があります。したがって、else句を追加し、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]; 
于 2012-09-11T20:38:13.200 に答える