objective-c - 重新加载 TableView 内容时出现 EXC_BAD_ACCES 错误

标签 objective-c ios xcode uitableview

正确填充数组后,当我使用 tableview 重新加载再次调用它时,第一次(清理后)返回一个空值,然后执行返回 EXC_BAD_ACCES。尝试提供所需的所有代码...感谢您的帮助!

在 .h 文件中:

    @interface userViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {

        NSArray *appData;

        IBOutlet UIActivityIndicatorView *activityIndicator;
        IBOutlet UILabel *status;
        IBOutlet UITableView *mainTable;
        IBOutlet UIBarButtonItem *refresh; 
    }

    @property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
    @property (nonatomic, retain) UILabel *status;
    @property (nonatomic, retain) UITableView *mainTable;
    @property (nonatomic, retain) UIBarButtonItem *refresh;
    @property (nonatomic, retain) NSArray *appData;

- (IBAction) refresca: (id)sender;

在 .m 文件中,当 requestFinished 函数执行时,appData 被正确填充。
- (void)requestFinished:(ASIHTTPRequest *)request {
    NSLog(@"%@", [request responseString]);
    [activityIndicator stopAnimating];
    activityIndicator.hidden = YES;

    appData = [[request responseString] componentsSeparatedByString: @"#"]; 

    int x =0;

    while (x<[appData count] - 1)
    {
        NSLog(@"Data = %@",[appData objectAtIndex: x]);
        x = x+1;
    }

}

然而,在它执行之后,当重新加载 tableview 时,appData 似乎是空的并且之前的 conted 被删除了!
2011-10-13 18:10:43.682 Nimbo[444:207] Data = <UITableViewCellContentView: 0x5c93dd0; frame = (0 0; 320 43); layer = <CALayer: 0x5c953b0>

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

        [tableView setFrame:CGRectMake(0, 44, 320, 412)];

        static NSString* cellIdentifier = @"cellIdentifier";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

        if(cell == nil)
        {
            cell = (UITableViewCell*) [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

        }
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.textLabel.backgroundColor = [UIColor clearColor];


        int x = 0;

        if ([appData count] != 0)
           {
           NSLog(@"Data = %@",[appData objectAtIndex: 0]);
            }

        return cell;
    }

最佳答案

看起来像您的实例变量 appData不保留。

编辑:正如其他人所说,使用该属性是最好的方法。这将保留您的新 appData以及之前分配的释放对象。

尝试改变:

    appData = [[request responseString] componentsSeparatedByString: @"#"]; 

到:
    self.appData = [[request responseString] componentsSeparatedByString: @"#"]; 

关于objective-c - 重新加载 TableView 内容时出现 EXC_BAD_ACCES 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7757237/

相关文章:

xcode - 您如何在 Unity/Mac 中重置或重新导入插件?

iphone - 读写属性和非原子赋值属性有什么区别?

c++ - iOS 处理强制应用程序退出的正确方法是什么

iphone - 使用 Objective-C 分割输入字符串

ios - MVVMCROSS ShowViewModel-Navigation继承类

iphone - 在 Xcode 4.2 和 iOS SDK 5.0 中使用 gcc 4.2

swift - Gamescene.swift 和 Gamescene.sks 不能一起工作

ios - Firebase 多位置更新最佳实践(包括示例)ios

iphone - 我怎样才能将加密数据插入sqlite。我在插入加密数据时遇到错误

iPhone多语言支持应用