'NSMutableArray'没有可见的@接口声明了选择器'appendData:'

时间:2012-12-09 05:25:32

标签: objective-c ios cocoa nsdata

我在iOS应用中使用EGOTableViewPullRefresh库。为了实现它,我不得不将原始类从UIViewController的子类更改为UITableViewController。这显然打破了我存储数据的方式,例如:在NSMutableArray中。

头:

#import <UIKit/UIKit.h>
#import "EGORefreshTableHeaderView.h"

@interface PullViewController : UITableViewController  <EGORefreshTableHeaderDelegate, UITableViewDelegate, UITableViewDataSource>{

    NSArray *news;
    NSMutableArray *data;

    EGORefreshTableHeaderView *_refreshHeaderView;

    //  Reloading var should really be your tableviews datasource
    //  Putting it here for demo purposes
    BOOL _reloading;
}

- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;

@end

实现:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    data = [[NSMutableData alloc] init];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData{
    [data appendData:theData];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    news = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    [self.tableView reloadData];
    [DejalBezelActivityView removeViewAnimated:YES];
}

3 个答案:

答案 0 :(得分:2)

我看不出您如何使用NSMutableArray代替NSMutableData。实际上,您只是实例化NSMutableData。因此,请将您的数据声明更改为类ivars中的NSMutableData类型。

答案 1 :(得分:2)

您将data声明为NSMutableArray,并且该类没有任何appendData:选择器。

答案 2 :(得分:1)

试试这个

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSMutableData *)theData{
    [data appendData:theData];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData{
    [data appendData:theData];
}

此外,

NSArray *news;
NSMutableArray *data; 

您确定数据类型是否合适?或者应该是NSMutableData..check一次:)