performSegueWithIdentifier if语句不起作用

时间:2012-05-21 16:39:31

标签: iphone objective-c ios uitableview

我有6个不同的表,当选择其中一个中的行时(在regionsFirstTable中,它对哪一个很重要)我希望它们执行一个segue。 regionsFirstTable的代码工作正常,但对于其他部分却没有 - segue只是不起作用。我知道它太乱了,但答案应该放在表面上。

- (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
}
} 

提前致谢!

P.S。我的所有表只有一个indexPath.section

1 个答案:

答案 0 :(得分:1)

在您的第一个{之后看起来有if个太多,因此if ( tableView == self.northAmericaFirstTable)的所有检查都没有达到,因为它全部嵌套在if (tableView == self.regionsFirstTable)中阻止

编辑:

这是固定代码,理论上

- (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
}