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

  • Home
  • SEARCH
  • 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 4598202
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:21:57+00:00 2026-05-21T23:21:57+00:00

i want to populate the tablecell with title and imageurl from xml list. i

  • 0

i want to populate the tablecell with title and imageurl from xml list.
i manage to store the title (NSMutableDictonary *sections )and imageURL (NSMutableDictonary *sectionsImg) into 2 NSMutableDictionary respectively.

/*******This is in viewDidLoad***/
Directory *allDirectory = [appDelegate.directories objectAtIndex:0];

for (allDirectory in appDelegate.directories)
{
    NSDictionary *dica = [NSDictionary dictionaryWithObject:allDirectory.dirTitle forKey:@"dirTitle"];
    NSDictionary *dico = [NSDictionary dictionaryWithObject:allDirectory.imageURL forKey:@"imageURL"];


    [dirName addObject:dica];
    [dirImage addObject:dico];
    //NSLog(@"dic of items : %@",dirImage);


}
for (allDirectory in appDelegate.directories)
{
    //retrieve the first letter from every directory title (dirTitle)
    NSString * c = [allDirectory.dirTitle substringToIndex:3];

    NSString * m = allDirectory.imageURL;



    found = NO;
    find = NO;

    for (NSString *str in [self.sections allKeys])
    {
        if ([str isEqualToString:c])
        {
            found = YES;
        }
    }
    for (NSString *stra in [self.sectionsImg allKeys])
    {
        if([stra isEqualToString:m])
        {
            find = YES;
        }
    }

    if (!found)
    {
            [self.sections setValue:[[NSMutableArray alloc]init] forKey:c ];
            [self.sectionsImg setValue:[[NSMutableArray alloc]init] forKey:m];
    }
    if (!find)
    {
        [self.sectionsImg setValue:[[NSMutableArray alloc]init] forKey:m];
    }

}

for (NSDictionary *directory in dirName)
{
    [[self.sections objectForKey:[[directory objectForKey:@"dirTitle"] substringToIndex:3]] addObject:directory];
    //NSLog(@"hehehe have : %@",sections);
}
for (NSDictionary *directoryImg in dirImage)
{
    //[[self.sectionsImg objectForKey:[[directoryImg objectForKey:@"imageURL"] substringFromIndex:0]] addObject:directoryImg];
    [[self.sectionsImg objectForKey:[directoryImg objectForKey:@"imageURL"]] addObject:directoryImg];

    //NSLog(@"HOHOHO have : %@",sectionsImg);
}

And on cellForRowAtIndexPath i declare a dictionary

NSDictionary *dictionary = [[self.sections valueForKey:[[[self.sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
cell.textLabel.text = [dictionary objectForKey:@"dirTitle"];

but when i tried to declare a dictionary for imageURL

NSDictionary *dictionaryImg = [[self.sectionsImg valueForKey:[[[self.sectionsImg allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];

it gives me a error :
Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘* -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]’

any idea why? the logic is supposed to be the same where xml title and url can be retrieve and be displayed. Title is retrievable but imageURL is not. Help is deeply appreciated !

  • 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-05-21T23:21:57+00:00Added an answer on May 21, 2026 at 11:21 pm

    You are trying to sort an array… except for the fact your array isn’t an array, but a NSDictionary.

    Your code isn’t the best at the moment. Your getting the idea of Dictionaries wrong and may be confusing them with arrays, so my best guess is your quite new to programming into objective-c.

    You have two lists of things, if I’m not mistaken. The first list is the list of names, and the second list is an image corresponding with that name.

    Below I’m going to do two things:

    • Firstly, I’m giving you two ways on how to fix your problem. It has a sample code included and gives you a small explanation with it. The possibility exist you don’t understand parts of what I describe. In that case, you should;
    • Check out the link I described below the two solutions. It has a tutorial which makes you understand everything about arrays, dictionaries, tables and, as a bonus, XML-parsing.

    So, in my opinion, you can do two things:


    The first one is using an array of NSDictionaries. You’d be using a code which looks like:

    NSMutableDictionary *itemOne = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *itemTwo = [[NSMutableDictionary alloc] init];
    NSMutableArray *listOfAll = [[NSmutableArray alloc] init];
    NSString *itemOneName = [[NSString alloc] initWithFormat:@"This is picture 1"];
    NSString *itemTwoName = [[NSString alloc] initWithFormat:@"This is picture 2"];
    NSData *imageOneData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"http://myurl/mypic1.jpg"]];
    NSData *imageTwoData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"http://myurl/mypic2.jpg"]];
    UIImage *itemOneImage = [UIImage imageWithData: imageOneData];
    UIImage *itemTwoImage = [UIImage imageWithData: imageTwoData];
    [itemOne setObject:itemOneNameString forKey:@"Name"];
    [itemOne setObject:itemOneImage forKey:@"Image"];
    [itemTwo setObject:itemTwoNameString forKey:@"Name"];
    [itemTwo setObject:itemTwoImage forKey:@"Image"];
    [listOfAll addObject:itemOne];
    [listOfAll addObject:itemTwo];
    

    Anything can be filled using that array. Just use something with a for-loop to iterate through your array.

    for (int i = 0; i < [listOfAll count]; i++)
    {
        NSMutableDictionary *currentItem = [[NSMutableDictionary alloc] initWithDictionary:[listOfAll objectAtIndex:i]];
        //Do something with that current item
    }
    

    You can also use that index in your tableView. In that case, you have to use your variable section instead of i to get your desired index.


    The second one is using two arrays. Imagine you get an image named imageOne with the text imageName. Then you should use:

    NSMutableArray *nameList = [[NSMutableArray alloc] init];
    [nameList addObject: imageName];
    NSMutableArray *imageList = [[NSMutableArray alloc] init];
    [imageList addObject: imageOne];
    

    If you want to use a certain item out of those lists, you just have to use the same indexnumber.
    For example:

    [theTitleLabel setText:[[NSString alloc] initWithFormat:@"%@", [nameList objectAtIndex:x]]];
    [theImageView setImage:[imageList objectAtIndex:x]];
    

    Make sure the x’s are the same number.


    I understand this is all a lot of information, especially if you’re new to Objective – C. A tutorial exists which gives you a lot of information about how to use arrays, dictionaries and table views. As a bonus, you get to know a little about XML-parsing.
    I suggest you walk through that tutorial and do everything and read everything it says. This should give you a nice start into the world of programming in iPhones.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table view that i want to populate with information from xml.
I want to populate a drop down list with values from database. <?php require
I want to populate a table, defined in layout xml file through the programmatic
I want to populate a drop down menu with a column from a MySQL
I want to populate a select list such that it increments for each 5
I have a UITableView which I want to populate with details from an array
I have an xml data file and I want to populate a listview in
I want to populate the weeks in a dropdown list when selecting month like
I want to populate one.plist files from a number of .plist files as per
Want to populate two NSMutableArray s to 2 Custom Sections of tableView ; I

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.