ios - 如何在搜索栏中使用 switch 命令

标签 ios uitableview xcode4.5 uisearchbar

我有一个用下面的数据编程的 TableView 。它还在页面上编程了一个有效的搜索功能。我正在尝试使用“切换”系统根据按下的单元格转移到特定的 View Controller 。

- (void)viewDidLoad
{
[super viewDidLoad];

smtArray = [[NSArray alloc] initWithObjects:
                    [Smt SSSOfCategory:@"P" name:@"HW"],
                    [Smt SSSOfCategory:@"P" name:@"WI"],
                    [Smt SSSOfCategory:@"P" name:@"WC"],
                    [Smt SSSOfCategory:@"P" name:@"C"],nil];

//搜索功能代码

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Smt *smt = nil;


if (tableView == self.searchDisplayController.searchResultsTableView) {
    smt = [filteredSmtsArry objectAtIndex:indexPath.row];


    switch (indexPath.row) {
        case 0:

            [self performSegueWithIdentifier:@"One" sender:self];
            break;

        case 1:
            [self performSegueWithIdentifier:@"Two" sender:self];
            break;

        default:
            break;
    }
}

}

目前,我对如何根据 tableview 单元格中的对象执行 segue 感到困惑。显然,目前 segues 依赖于 indexPath.row,这对于可搜索的表是无用的。 (我知道 segue 目前仅在数据被过滤后才有效)。

如有任何建议,我们将不胜感激!

干杯

最佳答案

你可以使用

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
        NSString *content = selectedCell.textLabel.text;

        if ([content isEqualToString:"One"]) [self performSegueWithIdentifier:@"One" sender:self];
        else if ([content isEqualToString:"Two"]) [self performSegueWithIdentifier:@"Two" sender:self];        
    }
}

在你的方法中。然后你可以从中得到任何你想要的东西。

关于ios - 如何在搜索栏中使用 switch 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14733668/

相关文章:

IOS Charts 折线图 View Double 值无法转换为 Int,因为要么是无穷大

ios - 在设备上使用 UIAutomation 进行录制时,它卡在 'Starting Capture...' 上。在模拟器上运行良好

ios - 为什么我取消选中设备方向后 iPhone 仍然旋转(从 info.plist 文件中删除旋转)

ios - 按下按钮时显示新的 SwiftUI View

objective-c - 多个 UITextfields 返回 Null IOS

objective-c - 在 ios 5 模拟器中使用时如何更改 UIPageControl 的颜色

objective-c - 使用 NavigationController 并在其中更改 View ,而无需推送 Nav 堆栈

ios - 为什么我无法运行 "pod update"?

swift - TableView ReloadSection 崩溃了吗?

ios - 添加和删​​除某个 UITableViewCell 下面的 UITableViewCell