传递到表视图数据源选择上的正确视图控制器

时间:2015-12-23 10:55:54

标签: ios objective-c

我正在根据选择加载具有两个不同plist的表视图单元格 -

问题是这个。在 MoreScreenOptionsData plist 中,所有元素都在那里,而 Guest_More plist 中的项目更少。所以基于条件我加载数组。

现在,当表在场景登录和注销中加载时,当选择行时,它总是重定向到 MoreScreenOptionsData plist 行索引值。它没有重定向到 Guest_More plist plist数组索引。

如果我加载访客屏幕

情景 - 如果用户已登录

- (NSArray *)moreScreenElements
 {
  NSString *plistPath;

  if ([VCConfiguration isUserAlreadyLoggedIn])
    plistPath = [[NSBundle mainBundle] pathForResource:@"MoreScreenOptionsData" ofType:@"plist"];
else
    plistPath = [[NSBundle mainBundle] pathForResource:@"Guest_More" ofType:@"plist"];

   moreScreenItems = [[NSArray alloc] initWithContentsOfFile:plistPath];
 return moreScreenItems;
 }

//表格视图行选择

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
switch (indexPath.row)
{
    case RowSelectedMethodMyOrder:
    {
        VCMyOrderViewController *myOrderVC = [self.storyboard instantiateViewControllerWithIdentifier:@"VCMyOrderViewController"];
        [self.navigationController pushViewController:myOrderVC animated:YES];
    }
        break;

    case RowSelectedMethodMyAddresses:
    {
        VCMyAddressViewController* infoController = [self.storyboard instantiateViewControllerWithIdentifier:@"VCMyAddressViewController"];
        [self.navigationController pushViewController:infoController animated:YES];
    }
        break;

    case  RowSelectedMethodTrackOrder:
    {
        VCTrackOrderViewController *myOrderVC = [self.storyboard instantiateViewControllerWithIdentifier:@"VCTrackOrderViewController"];
        [self.navigationController pushViewController:myOrderVC animated:YES];
    }
        break;

    case  RowSelectedMethodMyWallet:
    {

    }
        break;

    case RowSelectedMethodSetting:
    {

    }
        break;

    case RowSelectedMethodInviteFriends:
    {

    }
        break;

    case RowSelectedMethodRatetheApp:
    {
    }
        break;

    case RowSelectedMethodHelp:
    {
    }
        break;

    case RowSelectedMethodLogout:
    {
        [VCConfiguration clearLoggedUserData];
        moreScreenItems = [[NSArray alloc] initWithArray:[self moreScreenElements]];
        [self.tblMore reloadData];

        VCLoginViewController * loginVC = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"VCLoginViewController"];
        [loginVC setIsLoginForCart:NO];
        UINavigationController * navControllerLogin = [[UINavigationController alloc] initWithRootViewController:loginVC];
        [navControllerLogin setNavigationBarHidden:YES];
        [self presentViewController:navControllerLogin animated:YES completion:nil];
    }
        break;

    default:
        break;
}
}

1 个答案:

答案 0 :(得分:1)

在didSelectRowAtIndexPath中,您需要根据登录情况保留条件,就像您在moreScreenElements方法中所做的那样

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
      [tableView deselectRowAtIndexPath:indexPath animated:YES];
      if ([VCConfiguration isUserAlreadyLoggedIn]) {
         //Here you can write code for selecting MoreScreenOptionsData plist table cell
      } else {
          //Here you can write code for selecting Guest_More plist table cell 
      }
    }

如果您需要更多帮助,请告诉我

修改

经过与@imran的长时间讨论后,他需要根据行号和值进行相同的操作,因此我建议他在两个plist中使用相同的索引kay和值,并使用索引键来判断您在单元格选择中的操作。 / p>