Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9234677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:50:45+00:00 2026-06-18T06:50:45+00:00

I have created an array, two dictionaries and a tableview. The tableview should display

  • 0

I have created an array, two dictionaries and a tableview. The tableview should display the contents of array and that array contains the data of dictionaries. When i try to display it using “[mArray addObject:(mDictionary)];” its throwing an exception but if i use “[mArray addObject:[mDictionary objectForKey:@”firstname”]];” its working fine.

Can you help me to understand why is it happening and isn’t it possible to display the dictionary value without using “objectForKey”?

Here is my “ViewController.m”.

#import "ViewController.h"

@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    mArray = [[NSMutableArray alloc]init];
    mDictionary = [[NSMutableDictionary alloc]init];
    [mDictionary setValue:@"shanu" forKey:@"firstname"];
    [mDictionary setValue:@"kumar" forKey:@"lastname"];
    mDictionary2 = [[NSMutableDictionary alloc]init];
    [mDictionary2 setValue:@"hgjghjgf" forKey:@"firstname1"];
    [mDictionary2 setValue:@"ghjgjgfj" forKey:@"lastname1"];
    [mArray addObject:mDictionary];
    [mArray addObject:mDictionary2];

    CGRect frame = self.view.frame;
    UITableView *tableView = [[UITableView alloc]initWithFrame:frame style:UITableViewStylePlain];
    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    tableView.backgroundColor = [UIColor cyanColor];
    tableView.separatorColor = [UIColor blackColor];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"Array and Tableview";
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return mArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = [mArray objectAtIndex:indexPath.row];
    return cell;
}

- (void)dealloc
{
    [mArray release];
    [mDictionary release];
    [mDictionary2 release];
    [super dealloc];
}
@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:50:47+00:00Added an answer on June 18, 2026 at 6:50 am

    If you try to assign the some text to the cell’s textlabel the object returned from:

    [mArray objectAtIndex:indexPath.row];
    

    should be a string and not a whole dictionary.

    When you just put the whole dictionary in the array [mArray objectAtIndex:indexPath.row]; will return a dictionary and you cannot assign a dictionary to the textlabel so you get an exception. If you want to store the whole dictionary use objectForKey to get the string you want:

    cell.textLabel.text = [[mArray objectAtIndex:indexPath.row] objectForKey:@"WHAT_EVER_KEY_YOU_WANT"];
    

    btw, you are not using ARC zo you probably want to get an autoreleased UITableViewCell so add autorelease to you cell:

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
    

    or

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    [cell autorelease];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created two functions that sorts a list using bubble sort, but I
I have created an array and its data are shown in a tableview. Now
I have created an array in php that prints this Array ( [mark] =>
I have created an empty json object having an array itemlist(which further contains itemid
I have created two arrays. I wanna pass these two array to any function.
I have created a class that I've been using as the storage for all
I have created a function that creates a dynamic string array with dynamic string
I have created an array of coordinates. The centre of an image should move
I have created two models :User and UserProfile , Now I want display in
I have two plist files that I'm using as datasources to create NSArray and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.