简体   繁体   English

如何将变量传递给TabviewController?

[英]How to pass variable to TabviewController?

With the following code, I send data to a view controller, which then retrieves another set of data based on the ID variable that I send. 使用以下代码,我将数据发送到视图控制器,然后视图控制器根据我发送的ID变量检索另一组数据。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dict = [rows objectAtIndex: indexPath.row];

    ListingsViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"tabView"];

       controller.SUBSUBCATNAME = [dict objectForKey:@"S_NAME_EN"];

    controller.SUBSUBCATNUMBER = [dict objectForKey:@"SUBCAT_ID"];
    [self.navigationController pushViewController:controller animated:YES];

}

The next view loads another table that lists hotels in a country. 下一个视图会加载另一个列出某个国家/地区酒店的表格。 What I want to do is to put a tabview in between and filter hotels with the help of tabs. 我想要做的是在标签之间放置一个tabview并在标签的帮助下过滤酒店。 Forexample, the first tab will display all hotels, the second tab will display hotels in one region, the third tab another region and so on. 例如,第一个选项卡将显示所有酒店,第二个选项卡将显示一个区域中的酒店,第三个选项卡将显示另一个区域,依此类推。

My problem is when I send SUBSUBCATNUMBER to tabbarcontroller, it throws an error: 我的问题是当我将SUBSUBCATNUMBER发送到tabbarcontroller时,它会抛出一个错误:

'NSInvalidArgumentException', reason: '-[tabView setSUBSUBCATNUMBER:]: unrecognized selector sent to instance 

How can I send this ID to the tabbarcontroller which loads my view controller that lists all listings in that ID's category. 如何将此ID发送到tabbarcontroller,后者加载我的视图控制器,列出该ID类别中的所有列表。

You're breaking the naming rules, which is why it's failing. 你打破了命名规则,这就是它失败的原因。 Your ivar names should begin with a lowercase letter, so it should be called subSubCatNumber, or any other name, that begins with a lower case letter. 您的ivar名称应以小写字母开头,因此应将其称为subSubCatNumber或任何其他名称,以小写字母开头。 Change SUBSUBCATNUMBER to the above, or even sUBSUBCATNUMBER if you wish, but make the first letter lower case. 如果您愿意,可以将SUBSUBCATNUMBER更改为上述内容,甚至更改为sUBSUBCATNUMBER,但将第一个字母设为小写。 Only leave it capitalized if you explicitly call setSUBSUBCATNUMBER somewhere. 如果您在某处明确调用setSUBSUBCATNUMBER,则只保留大写。

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

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