gpt4 book ai didi

ios - 为什么数据给我空值?

转载 作者:行者123 更新时间:2023-11-28 21:33:16 25 4
gpt4 key购买 nike

我正在尝试将 NSDictionaryTableViewController 传递到 ViewController。在我的 TableViewController.m 中。我有这段代码可以导航到 ViewController:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *objectDict = [dataArray objectAtIndex:indexPath.row];
NSLog(@"Info: %@", objectDict);
// Pass object to new page
//UIViewController * vc = [[UIViewController alloc] init];
//[self presentViewController:vc animated:YES completion:nil];

SeeInfoVC *controller = [[SeeInfoVC alloc] init];
controller.data = objectDict;

NSString * storyboardName = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"SeeInfoVC"];
[self presentViewController:vc animated:YES completion:nil];

在我的 ViewController.h 中我有:

@interface SeeCardVC : UIViewController
{
NSDictionary *data;
}
@property (nonatomic, retain)NSDictionary *data;


@end

然后我尝试在 ViewController.m 中记录 data:

@implementation SeeCardVC
@synthesize data;

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"Info: %@", data);

}

但它只给我 null :(我究竟做错了什么?

最佳答案

让我们看看您的代码在这里做了什么:

// Create new controller, assign objectDict to data property
SeeInfoVC *controller = [[SeeInfoVC alloc] init];
controller.data = objectDict;

//Get Storyboard name
NSString * storyboardName = @"Main";
//Get Storyboard (BTW, you can do this with self.storyboard)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
//Instantiate NEW controller
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"SeeInfoVC"];
//Present NEW controller
[self presentViewController:vc animated:YES completion:nil];

您创建了一个 Controller 并为其分配了数据,然后不再使用它,而是从 Storyboard 中创建了一个新 Controller ,您没有添加数据并呈现它。

基本上,您创建了两个,将数据设置为一个并呈现另一个。

看到问题了吗?

关于ios - 为什么数据给我空值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34979413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com