ios - 如何使用 NSDictionary 将数据值传递给其他 ViewController Objective-C?

标签 ios objective-c uinavigationcontroller

我正在学习一本书中的教程,一切都很顺利,直到我不得不从 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 之间进行转换的代码,但是有一些值不属于我的代码,例如 recipeNamerecipeNames 如下所示:

recipeName 在我的代码 labelNamerecipeNames 在我的代码中是一个字典 [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/

相关文章:

ios - Swift 3.0 async Dispatch.global 不运行

ios - 滚动时如何使 UIScrollView 锁定 3 个 UIView 中的 2 个?

ios - 将 NSString 的 NSArray 转换为 NSNumber 的 NSArray 的更好方法

iphone - 无法通过 UINavigationcontroller.viewControllers 更改类的属性

ios - 贴纸包中缺少应用程序图标,但我已设置所有图标

ios - 为iPhone5S(arm64)编译Poco库

iOS 11 浏览器图像错误

objective-c - "First Responder"- 我做对了吗?

ios - 如何从一个导航 Controller 推送到多个 View Controller ?

ios - 如何将 UIImage 放置在 Navigationbar 中以使其成为 Logo ?