Retrieve a value from a table in a subview
From a view, I push a tableView where the back button is hidden. When one row is selected, the "back button" appear. I would like to pass to the value of the selected row as the user tap on the back button as content of a textField.
This is the code of the 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 = (NS开发者_如何学CString *) [rowVals objectForKey:@"key"];
[self ritornaValore];
}
valoreCategoria is a NSString declared in the .h
In AddItemController i have this "categoryNameField" where i would like to put inside the value of "valoreCategoria"
categoryNameField.text = ?
Before pushing CategoryListController
from AddItemController
you should save reference (i.e. categoryController
) to category list controller.
In viewWillAppear
of AddItemController
you should check if categoryController != nil
. If it is not nil, then you can try to retrieve value : categoryNameField.text = [categoryController ritornaValore];
. And if you don't need anymore categoryController
then you should release it self.categoryController = nil;
.
Check that categoryController
is defined as @property (nonatomic, retain) CategoryListController *categoryController;
and valoreCategoria
as @property (nonatomic, retain) NSString *valoreCategoria;
.
精彩评论