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 7490481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:36:53+00:00 2026-05-29T15:36:53+00:00

I have an iphone App that reads the category field from the xml file

  • 0

I have an iphone App that reads the “category” field from the xml file that is a rss feed. The way my App works is that it displays the content of the rss feed in a table view by categories from the xml “category” field.

Im a bit new to tableviews so im a bit lost.

I just have 2 categories on the xml file, one called “Uncategorized” and another called “Promos”.

The current code is:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case 0:         
            return itemsToDisplay.count;
        default:   
            return itemsToDisplay.count;
    }
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    if(section == 0)
        return @"Promoções";
    else
        return @"Não Categorizados";
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    if (indexPath.section == 0) {
        MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row];
        if([item.category isEqualToString:@"PROMOS"]){
            MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row];
            NSLog(@"ENTRA NO PROMOS____________________");
            NSLog(@"item.category = %@-------------->", item.category);
            // Process
            NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]";
            NSString *itemSummary = item.summary ? [item.summary stringByConvertingHTMLToPlainText] : @"[No Summary]";
            NSLog(@"IMAGE (table View) = %@",item.image);

            NSURL *url = [NSURL URLWithString:item.image];
            ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
            [request setDelegate:self];
            [request startAsynchronous];
            NSData * imageData = [NSData dataWithContentsOfURL:url];
            UIImage * image = [UIImage imageWithData:imageData];
            // Set
            cell.imageView.image = image;
            cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
            cell.textLabel.text = itemTitle;
            NSMutableString *subtitle = [NSMutableString string];
            if (item.date) [subtitle appendFormat:@"%@: ", [formatter stringFromDate:item.date]];
            [subtitle appendString:itemSummary];
            cell.detailTextLabel.text = subtitle;
            NSLog(@"FIM DO PROMOS_____________________");
        }
    }else if(indexPath.section == 1){
        MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row];
        if([item.category isEqualToString:@"Uncategorized"]){
            NSLog(@"ENTRA NO UNCATEGORIZED__________");
            NSLog(@"item.category = %@------------------>", item.category);
            // Process
            NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]";
            NSString *itemSummary = item.summary ? [item.summary stringByConvertingHTMLToPlainText] : @"[No Summary]";
            NSLog(@"IMAGE (table View) = %@",item.image);

            NSURL *url = [NSURL URLWithString:item.image];
            ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
            [request setDelegate:self];
            [request startAsynchronous];
            NSData * imageData = [NSData dataWithContentsOfURL:url];
            UIImage * image = [UIImage imageWithData:imageData];
            // Set
            cell.imageView.image = image;
            cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
            cell.textLabel.text = itemTitle;
            NSMutableString *subtitle = [NSMutableString string];
            if (item.date) [subtitle appendFormat:@"%@: ", [formatter stringFromDate:item.date]];
            [subtitle appendString:itemSummary];
            cell.detailTextLabel.text = subtitle;
            NSLog(@"FIM DO UNCATEGORIZED________________");
        }
    }
   return cell;
}

The problem i have is that it displays the same number of cells for both categories and doesn’t filter them by Categories.

Best Regards.

  • 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-29T15:36:53+00:00Added an answer on May 29, 2026 at 3:36 pm
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category = %@", @"PROMOS"];
    
    NSArray *promosArray = [itemsToDisplay filteredArrayUsingPredicate:predicate];
    
    switch (section) { 
    
        case 0:
    
            return [promosArray count];
        default:
    
            return [itemsToDisplay count] - [promosArray count];
    }
    

    For cell generation you should use this way too. Or you can prefilter data (for speed up)

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

Sidebar

Related Questions

I currently have an iPhone app that reads data from an external XML file
I'm developing an iPhone app. I've got a function that reads data from a
I have an old post Re-Installing IPhone App From Inside The App That old
I have an iPhone app that reads barcodes. I want to transfer that data
I have a Core Data iPhone app that displays Subscription entities where any of
I already have an iPhone App that stores data in a file in the
I have an iPhone app that hides the status bar. However, my main view
I have an iPhone app that compiles and runs fine in the Simulator on
I have an iPhone app that heavily relies on the OpenCV library; as such,
I have an iPhone app that is based on a navigation controller. I have

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.