小编sim*_*ode的帖子

如何使用Storyboard Dynamic Prototypes TableViewCell格式化SearchDisplayController结果

我创建了TableViewController子类并将其与故事板一起使用.我创建了1个动态原型并在子类中使用了它的Identifier值.它工作并显示故事板中显示的单元格.但是当我添加searchDisplayController并使TableViewController成为委托和数据源时,它会显示corrct搜索结果,但TableViewCells的格式不再遵循storyboard原型.我在下面使用的代码.我怎样才能让它跟随原型?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Contact Cell";
    static NSString *sCellID = @"Contact Cell";
    UITableViewCell *cell;
        if (tableView == self.searchDisplayController.searchResultsTableView) {
            cell = [tableView dequeueReusableCellWithIdentifier:sCellID];
            if (cell == nil) 
            {            
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:sCellID];
            }
        }
        else
        {
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) 
            {            
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            }
        }


    // ask NSFetchedResultsController for the NSMO at the row in question
    Contact *contact = [self.fetchedResultsController objectAtIndexPath:indexPath];
    // …
Run Code Online (Sandbox Code Playgroud)

objective-c storyboard searchdisplaycontroller ios

2
推荐指数
1
解决办法
2534
查看次数