繁体   English   中英

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

[英]Passing to correct view controller on table view datasource selection

我正在基于选择加载具有两个不同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;
}
}

在didSelectRowAtIndexPath中,您需要根据登录或不登录来保持条件,就像在moreScreenElements方法中所做的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进行了长时间的讨论后,他需要根据行数和值执行相同的操作,因此我建议他在两个指针中都使用相同的索引kay和值,并使用索引键来判断您在单元格选择中的操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM