我正在学习一本书中的教程,一切都很顺利,直到我不得不从 tableView 接收数据,我必须提到我修改了一些基本教程以满足我的需要,因为我使用来自的 JSON 值一个 API。当我使用 self 引用该值并说变量为零时,它崩溃了。还必须提到标签已添加为引用 socket ,并且 customClass
也已创建并添加到 View 中引用。除此之外,还添加了适当的 Segue 到 detailViewController
UserDetailViewController.h
@interface UserDetailViewController : UIViewController
@property (nonatomic, strong) NSString *labelName;
@property (nonatomic, strong) IBOutlet UILabel *detailLabelName;
@end
UserDetailViewController.m
这是在 Table 和 detailView
之间进行转换的代码,但是有一些值不属于我的代码,例如 recipeName
和 recipeNames
如下所示:
recipeName
在我的代码 labelName
上
recipeNames
在我的代码中是一个字典 [dictionary objectForKey:@"name"]
不知道如何将这部分放在一起。 :(
//这里是我处理数据传输的地方
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"userDetailView"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
RecipeDetailViewController *destViewController = segue.destinationViewController;
destViewController.recipeName = [recipeNames objectAtIndex:indexPath.row];
}
}
最佳答案
据我了解,您想根据labelName 为detailLbelName
设置文本。这个值来自你的父 View Controller 。
你一定是在做这样的事情:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UserDetailViewController *detailController = [[UserDetailViewController alloc]initWithNibName:@"UserDetailViewController" bundle:nil];
self.detailController.lableName = @"Your Text According to Cell"
[self.navigationController pushViewController:detailController animated:YES];
}
在您的 UserDetailViewController
中:
- (void)viewWillAppear
{
self.title = self.labelName;
[self.detailLabelName setText:self.labelName];
}
关于ios - 如何使用 NSDictionary 将数据值传递给其他 ViewController Objective-C?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23730038/