【问题标题】:tableView:cellForRowAtIndexPath: not getting called when using searchbartableView:cellForRowAtIndexPath:使用搜索栏时没有被调用
【发布时间】:2010-11-04 15:44:35
【问题描述】:

我有一个带笔尖的视图控制器 - 里面有一个表格视图、搜索栏和搜索显示控制器。

searchdisplaycontroller 的 contentscontroller、results delegate、delegate 和 results 数据源连接到 IB 中的 viewcontroller。搜索栏的委托连接到 IB 中的视图控制器。主表视图也在运行时正确连接到视图控制器及其加载项。

除了 resultstableview 之外,一切似乎都正常工作 - 它永远不会被填充,并且 tableView:cellForRowAtIndexPath: 在用户输入搜索栏后永远不会被调用 - 它只会被调用来填充主 tableview。

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

    // Dequeue or create a cell o f the appropriate type.
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    if (tableView.tag == 2)
    {
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

        // Configure the cell.
        NSHotel *selectedHotel = [[self hotelList] objectAtIndex:[indexPath row]];

        //Store the hotel id for use later
        selectedHotel.id = [indexPath row];

        //cell.textLabel.text = [NSString stringWithFormat:@"Catalonia Majorica", indexPath.row];
        cell.textLabel.text = [selectedHotel name];
    }
    else if (tableView.tag == 1)
    {
        cell.accessoryType = UITableViewCellAccessoryNone;

        // Configure the cell...    
        NSAirport *selectedAirport = nil;

        if (tableView == self.searchDisplayController.searchResultsTableView)
        {
            selectedAirport = [self.filteredListContent objectAtIndex:indexPath.row];
        }
        else
        {
            selectedAirport = [self.listContent objectAtIndex:indexPath.row];
        }

        //Set the label of the cell formatting the distance from the device 
        cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@ miles", 
                               selectedAirport.name, [self formattedStringWithDecimal:selectedAirport.milesFromDevice]];

        //Adjust the front of the label
        cell.textLabel.font = [UIFont boldSystemFontOfSize:12];

    }

    return cell;
}

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    已修复 - 它在此处返回 0:

     - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
        {
            if (tableView == self.searchDisplayController.searchResultsTableView)
            {
                return [self.filteredListContent count];
            }
            else if (tableView.tag == 1)
            {
                return [self.listContent count];
            }
            else if (tableView.tag == 2)
            {
                // Return the number of rows in the section.
                return [[self hotelList] count];
            }
    
            NSLog(@"The rows in tableview!");
            return 0;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多