【问题标题】:How to resolve property array not found on object of type "AppDelegate" error如何解决在“AppDelegate”类型的对象上找不到属性数组错误
【发布时间】:2012-07-25 10:05:36
【问题描述】:

我正在尝试使用以下代码发布到用户朋友的 FB 墙上。我被困在这条线上:** NSString *post=[[delegate.array objectAtIndex:tag.tag] objectForKey:@"id"];

**
错误消息:“在“AppDelegate”类型的对象上找不到属性数组

AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

        //Call the request method
        [[delegate facebook] requestWithGraphPath:@"me/friends" andDelegate:self];


        // get the array of friends                
        NSArray *data = [result objectForKey:@"data"];

        // Check that the user has friends
        if ([data count] > 0) {

            NSMutableArray *array = [NSMutableArray array];    
            for (int i = 0; i < data.count; i++){
                id object = [data objectAtIndex:i];
                [array addObject:[object objectForKey:@"name"]];
            }

            NSLog(@"list of friends %@", array);

            NSString *Message = [NSString stringWithFormat:@"-posted via iPhone App"];
            NSMutableDictionary *params1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                            Message, @"message", nil];
            NSString *post=[[delegate.array objectAtIndex:tag.tag] objectForKey:@"id"];

            [[delegate facebook] requestWithGraphPath:[NSString stringWithFormat:@"/%@/feed",post] andParams:params1 andHttpMethod:@"POST" andDelegate:self];

            UIAlertView  *alert = [[UIAlertView alloc] initWithTitle:@"Message!" message:@"Message Sent" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
            [alert release];

【问题讨论】:

  • 查看您的 AppDelegate.h,那里应该有一个声明的属性NSArray *array,如果缺少,请添加它。并在您的实施中综合
  • 谢谢。解决了数组警告。那么 NSString *post=[[delegate.array objectAtIndex:tag.tag] objectForKey:@"id"];我现在得到未声明的标识符“标签”。谢谢
  • 您还有两个称为数组的数组。我建议将它们命名为更有帮助的名称
  • 你必须声明那个标签,比如int tag和.tag,我相信它是一个错误的类型。
  • 什么是标签?它有标签属性吗?

标签: iphone objective-c ios facebook facebook-graph-api


【解决方案1】:

过去 3 天,我意识到您在 iphone 中获取 facebook 朋友时遇到了问题。所以我为你做一个演示。希望你喜欢这个。:)

Fetch Facebook friend here

【讨论】:

  • 如果你有问题要在用户墙上发帖告诉我,我会帮你的
  • 非常感谢!我遇到的问题是这段代码随机选择了一个朋友: kAPIFriendsForDialogFeed: { NSArray *resultData = [result objectForKey:@"data"]; // 检查用户是否有朋友 if ([resultData count] > 0) { // 随机选择一个朋友来发布提要 int randomNumber = arc4random() % [resultData count]; [self apiDialogFeedFriend:[[resultData objectAtIndex:randomNumber] objectForKey:@"id"]]; } else { [self showMessage:@"你没有朋友可以发帖。"]; }
  • 你在我的演示中看到了一个数组 FbFriendArray。当您获得随机数时,作为您的应用程序要求调用 sendFBPost 方法。
  • int randomNumber = arc4random() % [appDelegate.FBfriendArray count]];你可以用它来获取随机好友索引和这个传递randomNumber而不是tag.tag的功能
  • 你能把你的代码发到我的邮箱 mohit27bisht@gmail.com 我会修复它。
猜你喜欢
  • 2012-12-10
  • 2013-11-24
  • 1970-01-01
  • 1970-01-01
  • 2013-05-31
  • 1970-01-01
  • 2014-04-27
  • 2012-03-04
  • 1970-01-01
相关资源
最近更新 更多