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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:04:13+00:00 2026-06-14T18:04:13+00:00

I’ve got a UITableViewController which has a table view with custom cells (they have

  • 0

I’ve got a UITableViewController which has a table view with custom cells (they have a subclass and a xib). The thing is that I load data from a blog and it shows up ok, but when I try to scroll or touch, the cells reset, like if they weren’t loaded.

This is how it appears:
enter image description here

And this is what happens when I try to scroll:
enter image description here

This is my View Controller code:

#import "TLDRCategoryViewController.h"

@interface TLDRCategoryViewController ()
@property(nonatomic,strong) IBOutlet UIView *headerView;
@property(nonatomic,strong) NSMutableArray *posts;
@property(nonatomic, assign, readonly) TLDRTag category;
@property(nonatomic, strong) IBOutlet UILabel *category_label;
@end

@implementation TLDRCategoryViewController
@synthesize headerView = _headerView, posts = _posts, category = _category, category_label = _category_label;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)setCategory:(TLDRTag)_cat {
    _category = _cat;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView.tableHeaderView = _headerView;

    _category_label.text = [TLDRHelper showableNameForTag:_category];
    _category_label.textColor = [TLDRHelper colorForTag:_category];

    TLDRRetriever *retriever = [[TLDRRetriever alloc] initWithDelegate:self];
    [retriever postsByCategory:_category];
    if (_posts == nil)
        _posts = [[NSMutableArray alloc] init];


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)postsLoaded:(NSDictionary *)postsDict {

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) {
        for (NSDictionary *key in postsDict[@"response"][@"posts"]) {
            TLDRNewsItem *newsPost = [[TLDRNewsItem alloc] initWithDictionary:key];
            [self.posts addObject:newsPost];
        }
        dispatch_sync(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });

    });

}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

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

    // Return the number of rows in the section.
    return [self.posts count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"TLDRNewsCell";

    TLDRNewsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil){
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TLDRNewsCell" owner:nil options:nil];
        for(id currentObject in topLevelObjects) {
            if([currentObject isKindOfClass:[TLDRNewsCell class]]) {
                cell = (TLDRNewsCell *)currentObject;
                break;
            }
        }
    }


    cell.title.text = ((TLDRNewsItem*)self.posts[indexPath.row]).articleTitle;
    cell.content.text = ((TLDRNewsItem*)self.posts[indexPath.row]).articleTLDR;

    return cell;
}

-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *text = ((TLDRNewsItem*)self.posts[indexPath.row]).articleTLDR;

    CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(self.tableView.frame.size.width - PADDING * 3, 1000.0f)];

    return textSize.height + PADDING * 3;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}

And this is the relevant part of TLDRRetriever:

-(void)postsByCategory:(NSInteger)cat {
    NSString *string_cat = @"";

    switch (cat) {
        case TLDRTagWorldNews:
            string_cat = @"world%20news";
            break;
        case TLDRTagBusiness:
            string_cat = @"business";
            break;
        case TLDRTagDesign:
            string_cat = @"design";
            break;
        case TLDRTagEntertainment:
            string_cat = @"entertainment";
            break;
        case TLDRTagFacts:
            string_cat = @"facts";
            break;
        case TLDRTagHealth:
            string_cat = @"health";
            break;
        case TLDRTagPolitics:
            string_cat = @"politics";
            break;
        case TLDRTagScience:
            string_cat = @"science";
            break;
        case TLDRTagSports:
            string_cat = @"sports";
            break;
        case TLDRTagTech:
            string_cat = @"tech";
            break;
        case TLDRTagWeb:
            string_cat = @"web";
            break;

        default:
            string_cat = @"";
            break;
    }

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

    dispatch_async(queue, ^{
        NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kTLDRAPIURLCats, string_cat]]];
        NSError *error;
        NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

        [[self delegate] postsLoaded:json];

    });



}

I’ve got an almost exact view controller on that app as well and it works fine (I’m using most of the code of that controller, and this one will be reusable for other similar categories). This controller is allocated in batch (I allocate 11 of this controllers and save them in an array). I couldn’t debug this, so I don’t know what’s going on. Is there something wrong in the code? Thanks!

  • 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-14T18:04:15+00:00Added an answer on June 14, 2026 at 6:04 pm

    The fix wasn’t related with the controller or anything like that: it was the root view controller. The views weren’t being retained in memory, so I just made a ivar for every controller instead of looping through them and that fixed the app 🙂

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.