Obj-C:[__ NSArrayI length]:发送到实例的无法识别的选择器

时间:2017-06-15 05:09:23

标签: ios objective-c

我正在尝试将数据从NSMutableArray传递到NSDictionary。我似乎成功地做到了这一点,但是XCode试图在self.username.text中显示传递的数据时会让我崩溃。知道为什么会这样,以及如何解决它?请参阅下面的代码。

ViewController.m

 -(void)calloutTapped:(UITapGestureRecognizer *) sender
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    OtherUserViewController *yourViewController = (OtherUserViewController *)[storyboard instantiateViewControllerWithIdentifier:@"OtherUserViewController"];

    NSDictionary *dictionary = [[NSDictionary alloc] init];
    dictionary = [self.addressData mutableCopy];

    yourViewController.mapuserData = dictionary; 

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

}

OtherUserViewController.m

- (void)viewDidLoad {
[super viewDidLoad];

if (self.mapuserData != NULL) {
    NSLog(@"This is map user data %@", self.mapuserData);

    self.addFriend.hidden = NO;

    self.username.text = self.mapuserData[@"users_name"];
   NSLog(@"THIS IS IT %@", self.mapuserData[@"users_name"]);

    self.userBio.text = self.mapuserData[@"userbio"];

    NSString *thirdLink = self.mapuserData[@"photo_path"];

    NSString *ImageURLTwo = thirdLink;
    NSData *imageDataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURLTwo]];

    self.userPhoto.image = [[UIImage alloc] initWithData:imageDataTwo];


}

if (neighbourDetail == NULL) {

    self.addFriend.hidden = YES;

    self.username.text = [self.myFriendData objectForKey:@"node_title"];
    NSLog(@"this is friend detail %@", self.myFriendData);

    self.userBio.text = [self.myFriendData objectForKey:@"body"];

    NSString *thirdLink = [self.myFriendData objectForKey:@"friendphoto"];

    NSString *ImageURLTwo = thirdLink;
    NSData *imageDataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURLTwo]];

    self.userPhoto.image = [[UIImage alloc] initWithData:imageDataTwo];



} else {

     self.addFriend.hidden = NO;

    self.username.text = [neighbourDetail objectForKey:@"first name"];
    NSLog(@"this is neighbour detail %@", neighbourDetail);

    self.userBio.text = [neighbourDetail objectForKey:@"userbio"];

    NSString *secondLink = [neighbourDetail objectForKey:@"photo_path"];

    NSString *ImageURL = secondLink;
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];

    self.userPhoto.image = [[UIImage alloc] initWithData:imageData];


}


NSString *testing = [self.myFriendData objectForKey:@"node_title"];
NSLog(@"This is the testing value %@", testing);

NSArray *friendorNo = self.checkfriendData;
NSLog(@"Friend or No Value %@", friendorNo);


for (NSDictionary *dict in friendorNo) {
    if ([dict[@"node_title"] isEqualToString:testing]) {
        self.addFriend.hidden = YES;
    }
}

记录的数据成功传递给self.mapuserData:

2017-06-14 22:03:49.397526-0700[3706:1178771] This is user data (
        {
        address = "2957 chill street";
        childrenunder = Yes;
        city = Vancouver;
        "emergency facility" = None;
        "first name" = josh;
        "last name" = tree;
        phone = 688;
        "photo_path" = "x.png";
        "points balance" = 24;
        "postal code" = b6b6v5;
        "profile photo" = "<null>";
        "property type" = Apartment;
        province = ont;
        "special skills" = "None";
        "star rating" = 0;
        "street_address" = none;
        supervision = Yes;
        uid = 182;
        userbio = nfkkdkckmfkekxkx;
        "users_name" = "josh_tree@hotmail.com";
    }

2 个答案:

答案 0 :(得分:0)

您正在访问数组。

你可以试试这个:

_username.text = [self.mapuserData firstObject][@"users_name"]

所以,基本上self.mapUserContent是一个字典数组。我们做的是获取第一个对象,从第一个对象获取用户名。

让我知道这是否有效

答案 1 :(得分:0)

您正在尝试为objectForKey:对象调用NSArray

  

self.addressData是一种NSArray

<强> FIX:

NSDictionary *dictionary = [[NSDictionary alloc] init];
dictionary = [[self.addressData firstObject] mutableCopy];
yourViewController.mapuserData = dictionary;