【问题标题】:ios8 searchController searchResults custom cell is wrong heightios8 searchController searchResults自定义单元格高度错误
【发布时间】:2015-05-14 10:27:54
【问题描述】:

我使用Apple sample 作为构建searchController 方案的指南。一切正常,除了我不知道如何设置 SearchResultsController 单元格的高度。

主表视图和搜索结果表都指向同一个 Nib。颜色,字体和字体大小都可以。主表视图的高度还可以。

两个控制器都指向一个有两个标签的自定义笔尖。下面是一些图片和代码片段。

任何帮助(需要检查的东西?)将不胜感激..

自定义笔尖:

这是两个控制器的 cellAtIndexPath 代码(我省略了字体和颜色信息:

main controller:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
    StationCell *cell = (StationCell *)[self.tableView dequeueReusableCellWithIdentifier:kStationCellIdentifier];

    currentStationArray = stationListArray[indexPath.row];
    cell.stationLabel.text = [currentStationArray valueForKey:@"Name"];

    NSString *tempString = [currentStationArray valueForKey:@"LineCode1"];

    cell.lineLabel.text = tempString;

    return cell;
}

search result controller:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //NSLog(@"%s", __FUNCTION__);

    StationCell *cell = [tableView dequeueReusableCellWithIdentifier:kStationCellIdentifier];

    currentStationArray = [self.selectedStations objectAtIndex:indexPath.row];
    cell.stationLabel.text = [currentStationArray valueForKey:@"Name"];

    cell.stationLabel.font = [UIFont fontWithName:@"OrdredeDepart" size:24];
    cell.stationLabel.textColor = [UIColor yellowColor];
    cell.contentView.backgroundColor = [UIColor blackColor];
    cell.backgroundColor = [UIColor blackColor];

    NSString *tempString = [currentStationArray valueForKey:@"LineCode1"];

        cell.lineLabel.text = tempString;


    return cell;
}

最后,主单元格如下所示:

和搜索结果单元格,如下所示:

【问题讨论】:

    标签: objective-c uitableview ios8 uisearchcontroller


    【解决方案1】:

    你可以使用这个委托方法:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return 80.0f;
    }
    

    【讨论】:

    • 我试过了。它没有效果。欢迎其他想法,欢迎来到 SO。
    • 您是否将 tableView.delegate 设置为 self?
    • 如果您可以查看上面链接中的 Apple 示例,那就太好了。我已经检查并仔细检查了数据源和委托是否符合示例。
    • 你知道吗 - 你的答案是正确的。我再次尝试,将单元格高度放在主控制器中,它起作用了。我真的很感激。
    • 是的,你应该把它放在你放置tableview的控制器上。没问题:)
    猜你喜欢
    • 2016-02-04
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-27
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多