尝试显示评论数据

时间:2015-05-02 05:35:50

标签: ios objective-c uitableview instagram

我试图在详情视图控制器中显示Instagram评论。我正在从下面显示的主视图控制器推送数据:

MessageViewController *message = [[MessageViewController alloc] init];
NSInteger row = [[self tableView].indexPathForSelectedRow row];
NSDictionary *pic = [instaPics objectAtIndex:row];
message.instagramData = pic;
[self.navigationController pushViewController:message animated:YES];

然而,当我点击按钮转到详细视图控制器时,我收到此错误:

2015-05-02 01:29:56.464 Floadt[40646:4284271] Successfully commented Picture
2015-05-02 01:29:56.516 Floadt[40646:4284271] -[__NSCFArray objectForKeyedSubscript:]: unrecognized selector sent to instance 0x7fd06be6cc40
2015-05-02 01:29:56.529 Floadt[40646:4284271] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKeyedSubscript:]: unrecognized selector sent to instance 0x7fd06be6cc40'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010dc5bc65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010d537bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010dc630ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010dbb913c ___forwarding___ + 988
    4   CoreFoundation                      0x000000010dbb8cd8 _CF_forwarding_prep_0 + 120
    5   Floadt                              0x000000010a1104d0 -[MessageViewController messageCellForRowAtIndexPath:] + 256
    6   Floadt                              0x000000010a11035c -[MessageViewController tableView:cellForRowAtIndexPath:] + 188
    7   UIKit                               0x000000010c36ca28 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508
    8   UIKit                               0x000000010c34b248 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2853
    9   UIKit                               0x000000010c3618a9 -[UITableView layoutSubviews] + 210
    10  UIKit                               0x000000010c2eba2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
    11  QuartzCore                          0x000000010c0afec2 -[CALayer layoutSublayers] + 146
    12  QuartzCore                          0x000000010c0a46d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    13  UIKit                               0x000000010c2df675 -[UIView(Hierarchy) layoutBelowIfNeeded] + 607
    14  Floadt                              0x000000010a0908a8 -[SLKTextViewController viewWillAppear:] + 296
    15  UIKit                               0x000000010c39ffa1 -[UIViewController _setViewAppearState:isAnimating:] + 487
    16  UIKit                               0x000000010c3c1395 -[UINavigationController _startCustomTransition:] + 887
    17  UIKit                               0x000000010c3cd3bf -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
    18  UIKit                               0x000000010c3cdf0e -[UINavigationController __viewWillLayoutSubviews] + 43
    19  UIKit                               0x000000010c518715 -[UILayoutContainerView layoutSubviews] + 202
    20  UIKit                               0x000000010c2eba2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
    21  QuartzCore                          0x000000010c0afec2 -[CALayer layoutSublayers] + 146
    22  QuartzCore                          0x000000010c0a46d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    23  QuartzCore                          0x000000010c0a4546 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    24  QuartzCore                          0x000000010c010886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    25  QuartzCore                          0x000000010c011a3a _ZN2CA11Transaction6commitEv + 462
    26  QuartzCore                          0x000000010c0120eb _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
    27  CoreFoundation                      0x000000010db8eca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    28  CoreFoundation                      0x000000010db8ec00 __CFRunLoopDoObservers + 368
    29  CoreFoundation                      0x000000010db84a33 __CFRunLoopRun + 1123
    30  CoreFoundation                      0x000000010db84366 CFRunLoopRunSpecific + 470
    31  GraphicsServices                    0x000000010f611a3e GSEventRunModal + 161
    32  UIKit                               0x000000010c26b900 UIApplicationMain + 1282
    33  Floadt                              0x000000010a113c5f main + 111
    34  libdyld.dylib                       0x000000010fe26145 start + 1
    35  ???                                 0x0000000000000001 0x0 + 1
)

这是我将UITableViewCell添加到表视图控制器的设置代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     return [self messageCellForRowAtIndexPath:indexPath];
}

- (MessageTableViewCell *)messageCellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MessageTableViewCell *cell = (MessageTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:MessengerCellIdentifier];

    NSDictionary *instaPics = self.instagramData;
    NSString *commentText =  instaPics[@"comments"][@"data"][@"text"];

    Message *message = self.messages[indexPath.row];

    cell.titleLabel.text = message.username;
    cell.bodyLabel.text = commentText;

    if (message.attachment) {
        cell.attachmentView.image = message.attachment;
        cell.attachmentView.layer.shouldRasterize = YES;
        cell.attachmentView.layer.rasterizationScale = [UIScreen mainScreen].scale;
    }

    cell.indexPath = indexPath;
    cell.usedForMessage = YES;

    if (cell.needsPlaceholder)
    {
        CGFloat scale = [UIScreen mainScreen].scale;

        if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)]) {
            scale = [UIScreen mainScreen].nativeScale;
        }

        CGSize imgSize = CGSizeMake(kAvatarSize*scale, kAvatarSize*scale);

        [LoremIpsum asyncPlaceholderImageWithSize:imgSize
                                       completion:^(UIImage *image) {
                                           UIImage *thumbnail = [UIImage imageWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp];
                                           cell.thumbnailView.image = thumbnail;
                                           cell.thumbnailView.layer.shouldRasterize = YES;
                                           cell.thumbnailView.layer.rasterizationScale = [UIScreen mainScreen].scale;
                                       }];
    }

    // Cells must inherit the table view's transform
    // This is very important, since the main table view may be inverted
    cell.transform = self.tableView.transform;

    return cell;
}

Instagram JSON数据:

    {
    attribution = "<null>";
    caption =     {
        "created_time" = 1430594453;
        from =         {
            "full_name" = "Siwani Regmi";
            id = 247899182;
            "profile_picture" = "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/10948979_810376228999798_661235337_a.jpg";
            username = "siwani_32";
        };
        id = 976219494210952254;
        text = "perfect night with the most perfect man\Ud83d\Ude1b\Ud83c\Udf89\U2728 #seniorprom";
    };
    comments =     {
        count = 0;
        data =         (
        );
    };
    "created_time" = 1430594453;
    filter = Normal;
    id = "976219491862142549_247899182";
    images =     {
        "low_resolution" =         {
            height = 306;
            url = "https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s306x306/e15/11191276_1060001617348197_1550964556_n.jpg";
            width = 306;
        };
        "standard_resolution" =         {
            height = 640;
            url = "https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/e15/11191276_1060001617348197_1550964556_n.jpg";
            width = 640;
        };
        thumbnail =         {
            height = 150;
            url = "https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s150x150/e15/11191276_1060001617348197_1550964556_n.jpg";
            width = 150;
        };
    };
    likes =     {
        count = 17;
        data =         (
                        {
                "full_name" = "Bridget Carroll";
                id = 223765496;
                "profile_picture" = "https://igcdn-photos-e-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/11208422_409436919229236_670022667_a.jpg";
                username = "bridget_carroll33";
            },
                        {
                "full_name" = "";
                id = 190249955;
                "profile_picture" = "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xaf1/t51.2885-19/10747956_726218724133062_1939114518_a.jpg";
                username = hayleymarierussell;
            },
                        {
                "full_name" = "Jill Bracaglia";
                id = 205453413;
                "profile_picture" = "https://instagramimages-a.akamaihd.net/profiles/profile_205453413_75sq_1373835555.jpg";
                username = "jilli_beanz";
            },
                        {
                "full_name" = "Priya Nakhre";
                id = 177807366;
                "profile_picture" = "https://igcdn-photos-c-a.akamaihd.net/hphotos-ak-xtp1/t51.2885-19/11098479_870674976323434_1264837026_a.jpg";
                username = priyanakhre;
            }
        );
    };
    link = "https://instagram.com/p/2MOnSjQV5V/";
    location =     {
        id = 764529229;
    };
    tags =     (
        seniorprom
    );
    type = image;
    user =     {
        "full_name" = "Siwani Regmi";
        id = 247899182;
        "profile_picture" = "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/10948979_810376228999798_661235337_a.jpg";
        username = "siwani_32";
    };
    "user_has_liked" = 0;
    "users_in_photo" =     (
                {
            position =             {
                x = "0.358666667";
                y = "0.32";
            };
            user =             {
                "full_name" = "Sahan Pandey \U26bd";
                id = 435571613;
                "profile_picture" = "https://igcdn-photos-a-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/10727510_301263856731264_1868575282_a.jpg";
                username = pandeyexpress;
            };
        }
    );
}

0 个答案:

没有答案