Objective c 如何修复NSArray属性上的EXC_BAD_访问?

Objective c 如何修复NSArray属性上的EXC_BAD_访问?,objective-c,ios,nsarray,exc-bad-access,Objective C,Ios,Nsarray,Exc Bad Access,这是另一个EXC_BAD_访问问题。虽然我已经完成了我的家庭作业,并且确信我没有过度释放我的NSArray 下面是我的代码片段: tableData = [NSDictionary dictionaryWithJSONString:JSONstring error:&error]; //Collect Information from JSON String into Dictionary. Value returns a mutli dimensional NSDictionary.

这是另一个EXC_BAD_访问问题。虽然我已经完成了我的家庭作业,并且确信我没有过度释放我的NSArray

下面是我的代码片段:

tableData = [NSDictionary dictionaryWithJSONString:JSONstring error:&error];
//Collect Information from JSON String into Dictionary. Value returns a mutli 
dimensional NSDictionary. Eg: { value => { value => "null"}, etc }

NSMutableArray *t_info = [[NSMutableArray alloc] init];
for(id theKey in tableData)
{
    NSDictionary *get = [tableData objectForKey:theKey];
    [t_info addObject:get];
    [get release];
} // converting into an NSArray for use in a UITableView

NSLog(@"%@", t_info);
//This returns an Array with the NSDictionary's as an Object in each row. Returns fine

if (tvc == nil)
{
    tvc = [[tableViewController alloc] init]; //Create Table Controller
    tableView.delegate = tvc;
    tableView.dataSource = tvc;
    tvc.tableView = self.tableView;
    tvc.tableData = t_info; //pass our data to the tvc class
    [tvc.tableView reloadData];
}
...
现在在我的TableViewController类中:

@implementation tableViewController
@synthesize tableData, tableView;

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return [tableData count]; //Returns X Amount Fine.
}

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

    NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier"];

    UITableViewCell *cell = [the_tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
    }

    NSLog(@"%@", tableData); //** CRASHES!!**
    cell.textLabel.text = @"This is a test";
    return cell;
}
如果我要注释掉那个NSLog,它会工作得很好,并在每个表行上返回“thisatest”

这篇文章真的让我很困惑,所有关于这个问题的文章通常都与保留/内存问题有关

还有另一个要点。
如果我要从我的第一类代码中传递我的原始(NSDictionary)tableData并在tableViewController中运行相同的脚本,我可以很好地NSLog对象。

您需要释放对象的唯一时间是,如果您通过
new
alloc
copy
的方式显式分配它

NSMutableArray *t_info = [[NSMutableArray alloc] init];
for(id theKey in tableData)
{
    NSDictionary *get = [tableData objectForKey:theKey];
    [t_info addObject:get];
    [get release];
}
你不应该在这里发布
get
。这样做,您就释放了tableData字典保留的引用,这是不好的。我猜这就是你遇到的问题的原因


如果我没有弄错的话,
[tableData count]
返回预期值的原因是数组仍然保留已释放的引用。

您需要释放对象的唯一时间是,如果您通过
new
alloc
copy
明确分配了对象

NSMutableArray *t_info = [[NSMutableArray alloc] init];
for(id theKey in tableData)
{
    NSDictionary *get = [tableData objectForKey:theKey];
    [t_info addObject:get];
    [get release];
}
你不应该在这里发布
get
。这样做,您就释放了tableData字典保留的引用,这是不好的。我猜这就是你遇到的问题的原因


如果我没有弄错的话,
[tableData count]
返回预期值的原因是数组仍然保留着已发布的引用。

我会被诅咒的!谢谢,先生,没问题。在那里,我做到了,很高兴我能帮上忙!我会被诅咒的!谢谢,先生,没问题。在那里,我做到了,很高兴我能帮上忙!