【问题标题】:Retrieve a value from a table in a subview从子视图中的表中检索值
【发布时间】:2011-10-01 09:30:26
【问题描述】:

从一个视图中,我推了一个隐藏后退按钮的 tableView。 选择一行时,会出现“返回按钮”。 当用户点击后退按钮作为文本字段的内容时,我想传递给选定行的值。

这是tableView(CategoryListController.m)的代码:

-(NSString *)ritornaValore {
    return valoreCategoria;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationItem setHidesBackButton:NO animated:YES];
    NSDictionary *rowVals = (NSDictionary *) [categoryListItems objectAtIndex:indexPath.row];
    valoreCategoria = (NSString *) [rowVals objectForKey:@"key"];
    [self ritornaValore];
}

valoreCategoria 是在 .h 中声明的 NSString

在 AddItemController 中,我有这个“categoryNameField”,我想将其放入“valoreCategoria”的值中

categoryNameField.text = ?

【问题讨论】:

    标签: iphone objective-c uitableview uinavigationcontroller


    【解决方案1】:

    在从AddItemController 推送CategoryListController 之前,您应该将引用(即categoryController)保存到类别列表控制器。

    AddItemControllerviewWillAppear 中,您应该检查是否categoryController != nil。如果它不为零,那么您可以尝试检索值:categoryNameField.text = [categoryController ritornaValore];。如果你不再需要categoryController,那么你应该释放它self.categoryController = nil;

    检查categoryController 是否定义为@property (nonatomic, retain) CategoryListController *categoryController;valoreCategoria 定义为@property (nonatomic, retain) NSString *valoreCategoria;

    【讨论】:

    • 我已经按照你说的做了,但是“if”条件永远不会通过。 categoryController 始终为“nil”。
    • 你是在alloc+init之后设置的吗?
    • 你的意思是这样吗'- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; categoryController = [[CategoryListController alloc] init]; if (categoryController != nil) { categoryNameField.text = [categoryController ritornaValore]; } 类别控制器 = nil; }'
    • 好的,我修好了!最后,我使用了在 CategoryListController.m 中声明的 NSString 变量,而不是“valoreCategoria”。非常感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    • 1970-01-01
    • 2023-04-07
    • 2012-08-06
    • 1970-01-01
    相关资源
    最近更新 更多