Access Keys after adding NSDictionary to NSMutableArray. iOS

I have a NSDictionary that I add to a mutable array but when I try add the array to populate a uitableview I get an error.

  NSMutableArray *array = [[NSMutableArray alloc] init];
for (id element in self.categoriesMutableNameArray) {
    [array addObject:@"No"];
}

self.categoryDict = @{ @"title" : self.categoriesMutableNameArray, @"selected" : array};
self.categoryArr = [[NSMutableArray alloc] init];
self.categoryMutableDict = [NSMutableDictionary dictionaryWithDictionary:self.categoryDict];
[self.categoryArr addObject:self.categoryDict];

and the following categoryArr is printed like this:

2014-02-27 15:09:07.397 App[7982:70b] (
    {
    selected =         (
        No,
        No,
        No,
        No,
        No,
        No,
        No,
        No,
        No,
        No,
        No,
        No,
        No,
        No
    );
    title =         (
        "Fashion - Women",
        "Fashion - Men",
        Kids,
        "Accessories - Women",
        "Accessories - Men",
        "Styling / Hair",
        Inspiration,
        "Decoration / Architecture",
        "Great Places",
        "Art / Design",
        "Music / Movie / Books",
        "Food / Drink",
        "Gadgets / Tech",
        Rides
    );
}
) 

The trouble I am having is in the uitableview cellforrowatindexpath method I try and add the title key for the categoryArr to populate the uitableview and I get the following error on this line:

UILabel *categoryLabel = (UILabel *)[cell viewWithTag:111];
categoryLabel.text = [NSString stringWithFormat:@"%@",[[self.categoryArr objectAtIndex:indexPath.row] objectForKey:@"title"];

And the error log:

    2014-02-27 15:24:33.804 App[8153:70b] -[__NSArrayM length]: unrecognized selector sent to instance 0xa9bc3a0
2014-02-27 15:24:33.807 App[8153:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0xa9bc3a0'
*** First throw call stack:
(
    0   CoreFoundation                      0x020c75e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01e4a8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x02164903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x020b790b ___forwarding___ + 1019
    4   CoreFoundation                      0x020b74ee _CF_forwarding_prep_0 + 14
    5   Foundation                          0x006e18ed -[NSConcreteMutableAttributedString replaceCharactersInRange:withString:] + 39
    6   Foundation                          0x006e255a -[NSConcreteMutableAttributedString initWithString:attributes:] + 293
    7   UIKit                               0x01172bc6 -[UILabel _setText:] + 97
    8   UIKit                               0x01172d84 -[UILabel setText:] + 40
    9   App                             0x00047ebd -[PiccImageCategoriesViewController tableView:cellForRowAtIndexPath:] + 1533
    10  UIKit                               0x010b461f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
    11  UIKit                               0x010b46f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
    12  UIKit                               0x01098774 -[UITableView _updateVisibleCellsNow:] + 2378
    13  UIKit                               0x010abe95 -[UITableView layoutSubviews] + 213
    14  UIKit                               0x01030267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    15  libobjc.A.dylib                     0x01e5c81f -[NSObject performSelector:withObject:] + 70
    16  QuartzCore                          0x00c8e2ea -[CALayer layoutSublayers] + 148
    17  QuartzCore                          0x00c820d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    18  QuartzCore                          0x00c81f40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    19  QuartzCore                          0x00be9ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    20  QuartzCore                          0x00beae71 _ZN2CA11Transaction6commitEv + 393
    21  QuartzCore                          0x00beb544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    22  CoreFoundation                      0x0208f4ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    23  CoreFoundation                      0x0208f41f __CFRunLoopDoObservers + 399
    24  CoreFoundation                      0x0206d344 __CFRunLoopRun + 1076
    25  CoreFoundation                      0x0206cac3 CFRunLoopRunSpecific + 467
    26  CoreFoundation                      0x0206c8db CFRunLoopRunInMode + 123
    27  GraphicsServices                    0x027779e2 GSEventRunModal + 192
    28  GraphicsServices                    0x02777809 GSEventRun + 104
    29  UIKit                               0x00fc5d3b UIApplicationMain + 1225
    30  App                             0x0001406d main + 141
    31  libdyld.dylib                       0x02f4d70d start + 1
    32  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Thanks

Answers


Write this code

      categoryLabel.text = [[[self.categoryArr objectAtIndex:0] objectForKey:@"title"]objectAtIndex:indexPath.row];

instead OF

    categoryLabel.text = [NSString stringWithFormat:@"%@",[[self.categoryArr objectAtIndex:indexPath.row] objectForKey:@"title"];

And plz check that in UITableView dataSource methods i.e

 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [categoryLabel objectAtIndex:0]valueForKey:@"selected"].count;
}

OR

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [categoryLabel objectAtIndex:0]valueForKey:@"title"].count;
}

The return of [[self.categoryArr objectAtIndex:indexPath.row] objectForKey:@"title"]; is a array of NSString, categoryLabel.text = [NSString stringWithFormat:@"%@", /*the return array*/]; this is the problem.

Maybe what you want is:

NSArray *categoryDetailArr = [[self.categoryArr objectAtIndex:indexPath.section] objectForKey:@"title"];
categoryLabel.text =  [[categoryDetailArr  objectAtIndex:indexPath.row];

Need Your Help

CSS3 Linear Gradient in a circular way

html css css3 css-shapes

I am wondering if it is possible to do something like this with css gradients:

How to see logs in blackberry device?

logging blackberry qr-code

I am using ZXing 1.7 library for creating Barcode Sanner for Blackberry device.