mardi 5 mai 2015

Attempting to Display Array on to UITableView

I am attempting to display an array which I receive from a JSON Dictionary onto a UITableView but I keep getting an error. I am trying to display all the comments for a given Instagram Picture onto a Table. Here is how I am attempting to display the cells:

  MessageTableViewCell *cell = (MessageTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:MessengerCellIdentifier];

  NSDictionary *instaPics = self.instagramData;
  NSArray *commentArray =  instaPics[@"comments"][@"data"];
  NSString *commentText = [commentArray valueForKey:@"text"]; // Error occurs here

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

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

Here is the error I receive:

 -[__NSArrayI length]: unrecognized selector sent to instance 0x7f913052db10
2015-05-05 22:16:08.848 Floadt[6061:514032] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x7f913052db10'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000107d60c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010763cbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000107d680ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000107cbe13c ___forwarding___ + 988
    4   CoreFoundation                      0x0000000107cbdcd8 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x0000000106543ab4 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 65
    6   UIKit                               0x000000010654390f -[UILabel textRectForBounds:limitedToNumberOfLines:] + 76
    7   UIKit                               0x00000001065473b9 -[UILabel _intrinsicSizeWithinSize:] + 170
    8   UIKit                               0x0000000106547499 -[UILabel intrinsicContentSize] + 76
    9   UIKit                               0x00000001069e5b6c -[UIView(UIConstraintBasedLayout) _generateContentSizeConstraints] + 33
    10  UIKit                               0x00000001069e5930 -[UIView(UIConstraintBasedLayout) _updateContentSizeConstraints] + 422
    11  UIKit                               0x00000001069ecd25 -[UIView(AdditionalLayoutSupport) updateConstraints] + 162
    12  UIKit                               0x0000000106547304 -[UILabel updateConstraints] + 274
    13  UIKit                               0x00000001069ec346 -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 242
    14  UIKit                               0x00000001069ec53e -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
    15  CoreFoundation                      0x0000000107c67354 CFArrayApplyFunction + 68
    16  UIKit                               0x00000001069ec2ed -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 153
    17  Foundation                          0x0000000105b021be -[NSISEngine withBehaviors:performModifications:] + 155
    18  UIKit                               0x00000001069ec53e -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
    19  CoreFoundation                      0x0000000107c67354 CFArrayApplyFunction + 68
    20  UIKit                               0x00000001069ec2ed -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 153
    21  UIKit                               0x00000001069ec53e -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
    22  UIKit                               0x00000001069eca0e __60-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]_block_invoke + 96
    23  UIKit                               0x00000001069ec6d6 -[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded] + 231
    24  UIKit                               0x00000001067d7531 -[UITableViewCellContentView updateConstraintsIfNeeded] + 94
    25  UIKit                               0x00000001069ecdde -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeeded] + 146
    26  UIKit                               0x00000001063e4a3d -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 114
    27  UIKit                               0x00000001063f0a2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
    28  QuartzCore                          0x00000001061b4ec2 -[CALayer layoutSublayers] + 146
    29  QuartzCore                          0x00000001061a96d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    30  UIKit                               0x00000001063e4675 -[UIView(Hierarchy) layoutBelowIfNeeded] + 607
    31  Floadt                              0x0000000104195848 -[SLKTextViewController viewWillAppear:] + 296
    32  UIKit                               0x00000001064a4fa1 -[UIViewController _setViewAppearState:isAnimating:] + 487
    33  UIKit                               0x00000001064c6395 -[UINavigationController _startCustomTransition:] + 887
    34  UIKit                               0x00000001064d23bf -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
    35  UIKit                               0x00000001064d2f0e -[UINavigationController __viewWillLayoutSubviews] + 43
    36  UIKit                               0x000000010661d715 -[UILayoutContainerView layoutSubviews] + 202
    37  UIKit                               0x00000001063f0a2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
    38  QuartzCore                          0x00000001061b4ec2 -[CALayer layoutSublayers] + 146
    39  QuartzCore                          0x00000001061a96d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    40  QuartzCore                          0x00000001061a9546 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    41  QuartzCore                          0x0000000106115886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    42  QuartzCore                          0x0000000106116a3a _ZN2CA11Transaction6commitEv + 462
    43  UIKit                               0x000000010636d626 _UIApplicationHandleEventQueue + 2140
    44  CoreFoundation                      0x0000000107c94431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    45  CoreFoundation                      0x0000000107c8a2fd __CFRunLoopDoSources0 + 269
    46  CoreFoundation                      0x0000000107c89934 __CFRunLoopRun + 868
    47  CoreFoundation                      0x0000000107c89366 CFRunLoopRunSpecific + 470
    48  GraphicsServices                    0x0000000109716a3e GSEventRunModal + 161
    49  UIKit                               0x0000000106370900 UIApplicationMain + 1282
    50  Floadt                              0x0000000104218c5f main + 111
    51  libdyld.dylib                       0x0000000109f2b145 start + 1
    52  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Here is an example copy of the JSON:

{
    attribution = "<null>";
    caption =     {
        "created_time" = 1430877943;
        from =         {
            "full_name" = "Shreya M.";
            id = 25085898;
            "profile_picture" = "http://ift.tt/1KfELiO";
            username = "shreya_mandava";
        };
        id = 978597576956579585;
        text = "9+10????";
    };
    comments =     {
        count = 2;
        data =         (
                        {
                "created_time" = 1430878007;
                from =                 {
                    "full_name" = "Aleesha Toteja";
                    id = 17117902;
                    "profile_picture" = "http://ift.tt/1GZNFDM";
                    username = leeshtotes;
                };
                id = 978598112887967529;
                text = "DIRT \Ud83d\Ude3b";
            },
                        {
                "created_time" = 1430878307;
                from =                 {
                    "full_name" = "Shritha M.";
                    id = 375799796;
                    "profile_picture" = "http://ift.tt/1KfEHQl";
                    username = "shritha_m";
                };
                id = 978600630846098439;
                text = sigh;
            }
        );
    };
    "created_time" = 1430877943;
    filter = Normal;
    id = "978597574314167442_25085898";
    images =     {
        "low_resolution" =         {
            height = 306;
            url = "http://ift.tt/1GZNDvD";
            width = 306;
        };
        "standard_resolution" =         {
            height = 640;
            url = "http://ift.tt/1KfELiQ";
            width = 640;
        };
        thumbnail =         {
            height = 150;
            url = "http://ift.tt/1GZNFU0";
            width = 150;
        };
    };
    likes =     {
        count = 22;
        data =         (
                        {
                "full_name" = "Ronak Chopra";
                id = 347652824;
                "profile_picture" = "http://ift.tt/1KfELiU";
                username = "conak_rhopra";
            },
                        {
                "full_name" = "emily bach";
                id = 292615252;
                "profile_picture" = "http://ift.tt/1GZNDvF";
                username = "emily_bach_";
            },
                        {
                "full_name" = "\Ud83c\Udf38Trisha\Ud83c\Udf38";
                id = 303629882;
                "profile_picture" = "http://ift.tt/1KfELiW";
                username = trishddishh;
            },
                        {
                "full_name" = "Shritha M.";
                id = 375799796;
                "profile_picture" = "http://ift.tt/1KfEHQl";
                username = "shritha_m";
            }
        );
    };
    link = "http://ift.tt/1KfELiZ";
    location =     {
        id = 772010926;
        latitude = "38.913782928";
        longitude = "-77.383238738";
        name = "ft. dirt";
    };
    tags =     (
    );
    type = image;
    user =     {
        "full_name" = "Shreya M.";
        id = 25085898;
        "profile_picture" = "http://ift.tt/1KfELiO";
        username = "shreya_mandava";
    };
    "user_has_liked" = 0;
    "users_in_photo" =     (
                {
            position =             {
                x = "0.6703125";
                y = "0.246875";
            };
            user =             {
                "full_name" = "John Nguyen";
                id = 1477626916;
                "profile_picture" = "http://ift.tt/1GZNDLZ";
                username = bumbonguyen;
            };
        }
    );
}

Aucun commentaire:

Enregistrer un commentaire