【问题标题】:How to control UISearchDisplayController's own table view?如何控制 UISearchDisplayController 自己的表格视图?
【发布时间】:2009-12-21 09:47:18
【问题描述】:

在我的应用程序中,当我没有过滤我的表格时,当我点击一个单元格时,它的框架高度会增加,以显示一个 UIProgressView 来显示下载进度。

但是,当我使用 UISearchDisplayController 过滤获取的结果控制器数据时,此过滤后的表格视图中的单元格的行为方式不同。

相反,单元格不调整大小,不显示进度视图,不触发下载,应用程序随后崩溃。

如何控制使用UISearchDisplayController 过滤结果时显示的表格视图?

编辑

这是我的-tableView:didSelectRowAtIndexPath: 方法。它有点长,但要点是当我不搜索时它可以正常工作。

我认为我需要以某种方式对其进行调整,以便它可以与搜索结果控制器抛出的任何表视图/获取的结果控制器一起使用。

- (void) tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tv deselectRowAtIndexPath:indexPath animated:YES];

    if ([self.searchBar isFirstResponder])
        [self.searchBar resignFirstResponder];

    MyObject *_myObject = (MyObject *)[self.fetchedResultsController objectAtIndexPath:indexPath];

    if (self.isSimulatingFileHierarchy) 
    {   
        if ([_myObject isFolder]) 
        {
            ObjectsViewController *_objectsViewController = [[ObjectsViewController alloc] initWithNibName:@"ObjectsViewController" bundle:nil];
            _objectsViewController.managedObjectContext = self.managedObjectContext;
            _objectsViewController.nodeID = self.nodeID;
            _objectsViewController.nodeName = self.nodeName;
            _objectsViewController.parentObjectKey = [_myObject cleanedKey];

            if (self.parentObjectKey)
                _objectsViewController.title = [[_myObject cleanedKey] stringByTrimmingPrefix:[self.parentObjectKey stringByAppendingString:@"/"]];
            else 
                _objectsViewController.title = [_myObject cleanedKey];

            [self.navigationController pushViewController:_objectsViewController animated:YES];
            UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:self.title style:UIBarButtonItemStyleDone target:nil action:nil];
            self.navigationItem.backBarButtonItem = _backButton;
            [_backButton release];
            [_objectsViewController release];
        }
        else {
            //
            // If we don't have data cached for this object, we add a request for the object's bytes to the objectRequestQueue
            // 
            // 1. We add a progress indicator to the object's cell (we have an indexPath)
            // 2. We store the data to the Documents folder
            //
            // Once we have the data, we push a ViewerViewController subclass that is specific to the object content type 
            //

            if ((!_myObject.isDownloading) && ([_myObject.localPath length] == 0)) 
            {
                if ([AwsObject objectContentSupportedForType:[_myObject.contentType intValue]]) 
                {
                    //
                    // Start request and redraw row with UIProgressView
                    //
                    [self triggerObjectRequestAdditionForObject:_myObject atIndexPath:indexPath];
                }
                else {
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ObjectsViewObjectRequestUnsupportedTypeAlertViewTitle", @"") message:NSLocalizedString(@"ObjectsViewObjectRequestUnsupportedTypeAlertViewMessage", @"") delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"ObjectsViewObjectRequestUnsupportedTypeAlertViewContinue", @""), nil];
                    [alert show];
                    [alert release];
                }
            }
            else if ((_myObject.isDownloading) && ([_myObject.localPath length] == 0)) 
            {
                //
                // Cancel request and redraw row without progress view
                //
                [self triggerObjectRequestRemovalForObject:_myObject atIndexPath:indexPath];
            }
            else if ((!_myObject.isDownloading) && ([_myObject.localPath length] != 0)) 
            {
                //
                // Launch viewer for supported MIME type
                //
                switch ([_myObject.contentType intValue]) {
                    case kObjectContentTypeApplicationMsword: {
                        [self pushWebViewerViewController:_myObject withTextEncoding:@"UTF-8"];
                        break;
                    }
                    // handle other MIME types here...
                }
            }
            else {
                if ([_myObject isFolder]) { }
                else {
                    if ((!_myObject.isDownloading) && ([_myObject.localPath length] == 0))
                        [self triggerObjectRequestAdditionForObject:_myObject atIndexPath:indexPath];
                    else if ((_myObject.isDownloading) && ([_myObject.localPath length] == 0))
                        [self triggerObjectRequestRemovalForObject:_myObject atIndexPath:indexPath];
                    else if ((!_myObject.isDownloading) && ([_myObject.localPath length] != 0)) {
                        switch ([_myObject.contentType intValue]) {
                            case kObjectContentTypeApplicationMsword: {
                                [self pushWebViewerViewController:_myObject withTextEncoding:@"UTF-8"];
                                break;
                            }
                            // handle other MIME types here...
                        }
                    }
                }
            }
        }
    }
}

【问题讨论】:

    标签: iphone uitableview nsfetchedresultscontroller uisearchdisplaycontroller


    【解决方案1】:

    在任何表视图委托方法中,您可以通过以下检查来检测您是否正在使用 UISearchDisplayController 的表视图:

    if (tableView == self.searchDisplayController.searchResultsTableView) {
      // behavior specific to search display controller table view
    }
    else {
      // behavior specific to the original, unfiltered table view
    }
    

    【讨论】:

      【解决方案2】:

      通常,您会检查传递给tableView:didSelectRowAtIndexPath: 的表格视图是否等于您的搜索显示控制器的“searchResultsTableView”,并针对这种情况编写替代行为。

      听起来您的问题可能更复杂。可以发tableView:didSelectRowAtIndexPath:的代码吗?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-01
        相关资源
        最近更新 更多