这一直让我疯狂,并不确定发生了什么。我有一个UITableView,我填充UITableViewCells的内容,像这样iOS 7 UITableViewCell textLabel不保留文字
- (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;
}
包含行[细胞setNewsEntry:进入]取NewsEntry对象,并将细胞textLabel.text包含在条目的字符串。这在iOS 6中工作正常,但在iOS 7中标签不显示文本。
- (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]];
}
我已经在setNewsEntry中做了一些动作,如果我将self.textLabel.text设置为字符串常量,例如@“你好”,那么它工作正常。我也没有在setNewsEntry中使用很多NSLog,以确保a_newsEntry实际上具有有效的标题和摘要属性,但是由于某种原因,textLabel似乎并未保留它们。
起初我在想这是NewsEntry对象的一些内存问题,但它对我来说没有意义,为什么在iOS 7和iOS 6中会出现这种情况。不应该textLabel.text属性保留它被设置为的NSString?
如果任何人有任何想法,为什么发生这种情况请让我知道,我可以提供任何问题的答案你有。
谢谢。
编辑:NewsEntry接口
@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
请问您可以添加NewsEntry界面吗? –
嘿,我刚刚添加它 – strikerdude10
尝试添加'copy'到你的'NSString's。因此,而不是'(非原子,只读)'使用'(非原子,只读,复制)'。不知道这是否是问题,只是我脑海中浮现的第一件事。 –