Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios tableView和解除分配的实例存在问题_Ios_Objective C_Memory Management_Tableview - Fatal编程技术网

Ios tableView和解除分配的实例存在问题

Ios tableView和解除分配的实例存在问题,ios,objective-c,memory-management,tableview,Ios,Objective C,Memory Management,Tableview,使用XCode(4.6)提供的主视图模板创建一个简单的RSS提要阅读器 应用程序加载第一个满是标题的屏幕,然后向下或向上滚动时,会出现错误 我在控制台中收到的错误是: [__NSArrayM retain]: message sent to deallocated instance 0x7522d40 跟踪将我引导到CellForRowatinex函数中的这一行。XCode将该行标记为信号SIGKILL。(这可能是因为我按照调试教程中的说明设置了僵尸对象) 下面是该函数的其余部分 - (UIT

使用XCode(4.6)提供的主视图模板创建一个简单的RSS提要阅读器

应用程序加载第一个满是标题的屏幕,然后向下或向上滚动时,会出现错误

我在控制台中收到的错误是:

[__NSArrayM retain]: message sent to deallocated instance 0x7522d40
跟踪将我引导到CellForRowatinex函数中的这一行。XCode将该行标记为信号SIGKILL。(这可能是因为我按照调试教程中的说明设置了僵尸对象)

下面是该函数的其余部分

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

NSString * cellId = @"feeds";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellId];

if(cell == nil){
    cell = [[UITableViewCell alloc] init];
    NSMutableDictionary * news = (NSMutableDictionary *)[self.nf.newsStories objectAtIndex:indexPath.row];
    [cell.textLabel setText:[news objectForKey:@"title"]];
}

return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.nf = [[NewsFeed alloc]init];
[self.nf setFeedURL:[NSURL URLWithString:@"http://rss.cnn.com/rss/cnn_topstories.rss"]];
[self.nf retrieveFromInternet];

//For debugging. 
for(id newsItem in self.nf.newsStories){
    NSDictionary * d = (NSDictionary *)newsItem;
    NSLog(@"Title: %@\nDescription: %@", [d objectForKey:@"title"], [d objectForKey:@"description"]);
}

}
这是我的viewDidLoad函数

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

NSString * cellId = @"feeds";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellId];

if(cell == nil){
    cell = [[UITableViewCell alloc] init];
    NSMutableDictionary * news = (NSMutableDictionary *)[self.nf.newsStories objectAtIndex:indexPath.row];
    [cell.textLabel setText:[news objectForKey:@"title"]];
}

return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.nf = [[NewsFeed alloc]init];
[self.nf setFeedURL:[NSURL URLWithString:@"http://rss.cnn.com/rss/cnn_topstories.rss"]];
[self.nf retrieveFromInternet];

//For debugging. 
for(id newsItem in self.nf.newsStories){
    NSDictionary * d = (NSDictionary *)newsItem;
    NSLog(@"Title: %@\nDescription: %@", [d objectForKey:@"title"], [d objectForKey:@"description"]);
}

}

任何帮助都将不胜感激。谢谢各位

由于某些原因,我无法添加评论,但您应该移动

NSMutableDictionary * news = (NSMutableDictionary *)[self.nf.newsStories objectAtIndex:indexPath.row];
    [cell.textLabel setText:[news objectForKey:@"title"]];
在有条件的情况下。。。我不知道你为什么要让它变。此外,将单元格起始更改为:

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: cellId];

除此之外,如果您正在使用ARC,请确保您的新闻提要中的数组的属性设置为strong。

尝试用initWithStyle:reuseIdentifier:替换init,当您创建单元格时——这是实例化单元格的常用方法。将可变字典更改为仅字典并检查??嗯。仍然抛出相同的错误。我想知道问题是否出在我的NewsFeed实现中。谢谢你给我提建议。