Ios 为什么这些信息没有从一个类传递到另一个类

Ios 为什么这些信息没有从一个类传递到另一个类,ios,objective-c,class,Ios,Objective C,Class,我试图将这些信息从名为ViewController的类发送到另一个类。在viewController中,我有一个名为selectedvices的NSDictionary。然后在另一个类中,我还有一个名为selectedvictions的NSDictionary。我想将信息从ViewController selectedvinces发送到另一个类的selectedvinces,但它只返回null ViewController *main = nil; self.selectedVenue = ma

我试图将这些信息从名为
ViewController
的类发送到另一个类。在
viewController
中,我有一个名为
selectedvices
NSDictionary
。然后在另一个类中,我还有一个名为
selectedvictions
NSDictionary
。我想将信息从
ViewController selectedvinces
发送到另一个类的selectedvinces,但它只返回null

ViewController *main = nil;
self.selectedVenue = main.selectedVenues;
NSDictionary *selectedLocation = self.selectedVenue[@"location"];
NSString *selectedLat = selectedLocation[@"lat"];
NSString *selectedLng = selectedLocation[@"lng"];
我现在已经试过了。但它仍然不起作用

ViewController *main = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];

       //self.selectedVenue = main.selectedVenues;
       NSDictionary *selectedLocation =  [main getSelectedVenue:@"location"];
       NSString *selectedLat = selectedLocation[@"lat"];
       NSString *selectedLng = selectedLocation[@"lng"];
这是我的viewController中的方法

-(NSDictionary *)getSelectedVenue:(NSString *)key;
{

    NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
    self.selectedVenue= [self.venues objectAtIndex:selectedIndexPath.row];
     NSDictionary *selectedLocation = self.selectedVenue[key];

    return selectedLocation;

}
当您引用
nil
值时,您预期会发生什么

但它只返回null

ViewController *main = nil;
self.selectedVenue = main.selectedVenues;
NSDictionary *selectedLocation = self.selectedVenue[@"location"];
NSString *selectedLat = selectedLocation[@"lat"];
NSString *selectedLng = selectedLocation[@"lng"];
是的,这是有效的

当您引用
nil
值时,您预期会发生什么

但它只返回null

ViewController *main = nil;
self.selectedVenue = main.selectedVenues;
NSDictionary *selectedLocation = self.selectedVenue[@"location"];
NSString *selectedLat = selectedLocation[@"lat"];
NSString *selectedLng = selectedLocation[@"lng"];

是的,这是有效的。

您需要初始化
viewController
,以便在代码中获取其字典值

ViewController *main = nil;
您应该使用nib或正在使用的viewController对其进行初始化

ViewController *main = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];

您需要初始化
viewController
,以便在代码中获取其字典值

ViewController *main = nil;
您应该使用nib或正在使用的viewController对其进行初始化

ViewController *main = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];

在按下viewController之前传递该值

在ViewController.m中

NextViewController *main = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
main.selectedVenue = self.selectedVenue;

[self.navigationController pushViewController:main animated:YES];

在按下viewController之前传递该值

在ViewController.m中

NextViewController *main = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
main.selectedVenue = self.selectedVenue;

[self.navigationController pushViewController:main animated:YES];

您是否正在尝试访问
nil
selectedVinces
?您必须
init
您的ViewController。需要更多的代码,但是为什么要复制数据(为什么不向
ViewController
添加一个只获取您感兴趣的位置的方法)-特洛伊木马程序我已经采纳了您的建议,但它仍然不起作用。您是否正在尝试访问
nil
selectedvictions
?您必须
init
您的ViewController。需要更多的代码,但为什么要复制数据(为什么不在
ViewController
中添加一个只获取您感兴趣的位置的方法呢)?-特洛伊木马我接受了你的建议,但它仍然不起作用。不需要为新的而道歉,我们都有过一段时间。你很幸运你使用了Objective C,但是在许多语言中,使用空值会导致程序崩溃。不需要为新的而道歉,我们都有过一段时间。你很幸运你使用了Object然而,在许多语言中,使用空值会导致程序崩溃。