简体   繁体   中英

iOS 7 UITableViewCell textLabel not retaining text

This has been driving me crazy and not really sure whats going on. I have a UITableView and I'm populating the content of the UITableViewCells like so

- (UITableViewCell *)tableView:(UITableView *)a_tableView cellForRowAtIndexPath:(NSIndexPath *)a_indexPath
{
    NewsItemCell * cell = (NewsItemCell *)[a_tableView dequeueReusableCellWithIdentifier:@"NewsItemCell"];
    if(cell == nil)
    {
        cell = [[[NewsItemCell alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0)] autorelease];

    }
    if(!m_isLoading)
    {
        NewsFeed * feed = [NewsFeed sharedNewsFeed];
        NewsEntry * entry = [[feed feedEntries] objectAtIndex:[a_indexPath row]];

        [cell setNewsEntry:entry];
    }
    else 
    {
        if([a_indexPath row] < [m_visibleCells count])
        {
            return [m_visibleCells objectAtIndex:[a_indexPath row]];
        }
    }

    return cell;
}

The line that contains [cell setNewsEntry:entry] takes the NewsEntry object and sets the cells textLabel.text to a string contained in entry. This works fine in iOS 6 but in iOS 7 the labels aren't showing the text.

- (void)setNewsEntry:(NewsEntry *)a_newsEntry
{
    self.textLabel.text = a_newsEntry.title;
    self.detailTextLabel.text = a_newsEntry.summary;
    self.imageView.image = [self getIconForFeedType:[a_newsEntry feedType]];   
}

I've done some poking around and in setNewsEntry and if I set self.textLabel.text to a string literal eg @"hello" then it works fine. I've also don't a lot of NSLogs inside of setNewsEntry to make sure that a_newsEntry actually has a valid title and summary properties, it does but for some reason the textLabel doesn't seem to be retaining them.

At first I was thinking that this was some memory issue with NewsEntry object but it doesn't make sense to me why this would be the case in iOS 7 and not iOS 6. Shouldn't the textLabel.text property retain the NSString that it gets set to?

If anyone has any ideas as to why this is happening please let me know and I can provide answers to any questions you have.

Thank you.

EDIT: NewsEntry Interface

@interface NewsEntry : NSObject
{
    NSString * m_title;
    NSString * m_summary;
    NSString * m_published;
    NSString * m_updated;
    NSString * m_link;
    int m_feedType;
}

@property (nonatomic, readonly) NSString * title;
@property (nonatomic, readonly) NSString * summary;
@property (nonatomic, readonly) NSString * published;
@property (nonatomic, readonly) NSString * updated;
@property (nonatomic, readonly) NSString * link;
@property (nonatomic, readonly) int feedType;

- (NSDictionary *)properties;
- (NewsEntry *)initWithProperties:(NSDictionary *)a_properties;
- (NSComparisonResult)compareEntry:(NewsEntry *)entry;

@end

Where you able to resolve it? I have a similar issue where the detailTextLabel does not get updated on iOS7 whereas it works fine on iOS6. In my case, if I present another view on top and than go back to the tableview, I see the label updated already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM