iphone - PerformSegueWithIdentifier if 语句不起作用

标签 iphone objective-c ios uitableview

我有 6 个不同的表,当选择其中一个表中的行时(在 RegionFirstTable 中,哪个表很重要),我希望它们执行 Segue。 regionsFirstTable 的代码工作正常,但至于其他部分却不行——segues 不起作用。我知道这太困惑了,但答案应该就在表面上。

- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if (tableView == self.regionsFirstTable) {
    {     if (indexPath.row==0)
        if (indexPath.section==1) {
            [self performSegueWithIdentifier:@"toAfricanFS" sender:indexPath];
        } else {
            [self performSegueWithIdentifier:@"toAfricanFS" sender:indexPath];
        }
        if (indexPath.row==1)
            if (indexPath.section==1) {
                [self performSegueWithIdentifier:@"toAsiaFS" sender:indexPath];

            } else {
                [self performSegueWithIdentifier:@"toAsiaFS" sender:indexPath];
            }
        if (indexPath.row==2)
            if (indexPath.section==1) {
                [self performSegueWithIdentifier:@"toEuropeFS" sender:indexPath];

            } else {
                [self performSegueWithIdentifier:@"toEuropeFS" sender:indexPath];
            }
        if (indexPath.row==3)
            if (indexPath.section==1) {
                [self performSegueWithIdentifier:@"toLatinFS" sender:indexPath];
            } else {
                [self performSegueWithIdentifier:@"toLatinFS" sender:indexPath];
            }
        if (indexPath.row==4)
            if (indexPath.section==1) {
                [self performSegueWithIdentifier:@"toNorthAmericaFS" sender:indexPath];
            } else {
                [self performSegueWithIdentifier:@"toNorthAmericaFS" sender:indexPath];
            }
    } //Dealing with the first UITableView, it works

    if (tableView == self.africaFirstTable) {
        [self performSegueWithIdentifier:@"fromAfricatoDone" sender:indexPath];
    } 
    if (tableView == self.asiaFirstTable) {
        [self performSegueWithIdentifier:@"fromAsiatoDone" sender:indexPath];
    } 
    if (tableView == self.europeFirstTable) {
        [self performSegueWithIdentifier:@"fromEuropetoDone" sender:indexPath];
    }
    if (tableView == self.latinAmericaFirstTable) {
        [self performSegueWithIdentifier:@"fromLatintoDone" sender:indexPath];
    } 
    if (tableView == self.northAmericaFirstTable) {
        [self performSegueWithIdentifier:@"fromNorthAmericatoDone" sender:indexPath];
    } //This whole thing is not working as it should be
}
} 

提前致谢!

附言我的所有表都只有一个indexPath.section

最佳答案

看起来你有太多{在您的第一个 if 之后,所以您对 if ( tableView == self.northAmericaFirstTable) 的所有检查没有命中,因为它全部嵌套在 if (tableView == self.regionsFirstTable) 中 block

编辑:

理论上这是固定代码

- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if (tableView == self.regionsFirstTable) {
     if (indexPath.row==0)
        if (indexPath.section==1) {
            [self performSegueWithIdentifier:@"toAfricanFS" sender:indexPath];
        } else {
            [self performSegueWithIdentifier:@"toAfricanFS" sender:indexPath];
        }
        if (indexPath.row==1)
            if (indexPath.section==1) {
                [self performSegueWithIdentifier:@"toAsiaFS" sender:indexPath];

            } else {
                [self performSegueWithIdentifier:@"toAsiaFS" sender:indexPath];
            }
        if (indexPath.row==2)
            if (indexPath.section==1) {
                [self performSegueWithIdentifier:@"toEuropeFS" sender:indexPath];

            } else {
                [self performSegueWithIdentifier:@"toEuropeFS" sender:indexPath];
            }
        if (indexPath.row==3)
            if (indexPath.section==1) {
                [self performSegueWithIdentifier:@"toLatinFS" sender:indexPath];
            } else {
                [self performSegueWithIdentifier:@"toLatinFS" sender:indexPath];
            }
        if (indexPath.row==4)
            if (indexPath.section==1) {
                [self performSegueWithIdentifier:@"toNorthAmericaFS" sender:indexPath];
            } else {
                [self performSegueWithIdentifier:@"toNorthAmericaFS" sender:indexPath];
            }
    } //Dealing with the first UITableView, it works

    if (tableView == self.africaFirstTable) {
        [self performSegueWithIdentifier:@"fromAfricatoDone" sender:indexPath];
    } 
    if (tableView == self.asiaFirstTable) {
        [self performSegueWithIdentifier:@"fromAsiatoDone" sender:indexPath];
    } 
    if (tableView == self.europeFirstTable) {
        [self performSegueWithIdentifier:@"fromEuropetoDone" sender:indexPath];
    }
    if (tableView == self.latinAmericaFirstTable) {
        [self performSegueWithIdentifier:@"fromLatintoDone" sender:indexPath];
    } 
    if (tableView == self.northAmericaFirstTable) {
        [self performSegueWithIdentifier:@"fromNorthAmericatoDone" sender:indexPath];
    } //This whole thing is not working as it should be
} 

关于iphone - PerformSegueWithIdentifier if 语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10689122/

相关文章:

c++ - iOS,objective-c 代码中的 shared_ptr 生命周期?

ios - 直接在类上实现时类别方法无效

iphone - XCode/Objective C 基于调用者的条件断点

iphone - XCode 在 "Run Script"阶段未完成测试构建

ios - 从不带导航栏的 View Controller 推送/弹出带导航栏的 View Controller

ios - 以编程方式触发 textFieldShouldClear

ios - removeFromSuperview 随机崩溃

ios - 我可以使用 UILocalNotifications 和 UNUserNotifications 吗?

ios - 在 iOS 上通过蓝牙进行类似 TLS 的加密?

iphone - 我的 NSDateFormatter 脚本中存在重大泄漏