当我尝试更改在我的 StreamScreen UIViewController 类中声明的@property 时,我收到一个(lldb)错误。
我正在尝试更改 asyncRequest 成功块中的 feedList 对象。asyncRequest 方法是我导入的一个类方法,它是我的名为 NSURLConnection-block 的类的一部分。
所以...
我正在尝试更改一个 NSMutableArray (feedList),它是 StreamScreen 中的一个块内的 StreamScreen 的一部分,并且该块由另一个类的类方法 (asyncRequest) 调用,但我收到错误。
在调试导航器中,我得到 -error: address doesn't contain a section that points to a section in a object file
这是我的一些代码...
这是我声明 feedList @property (StreamScreen.h) 的地方
@property (strong, nonatomic) NSMutableArray *feedList;
下面的代码是(StreamScreen.m)中带有asyncRequest类方法的getStream方法
- (void)getStream {
NSString *fbAccessToken = [[[FBSession activeSession] accessTokenData] accessToken];
NSString *urlString = [NSString stringWithFormat: @"http://198.199.71.169/getFB.php?at=%@", fbAccessToken];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[NSURLConnection asyncRequest:request
success:^(NSData *data, NSURLResponse *response) {
NSLog(@"%@", feedList);
}
failure:^(NSData *data, NSError *error) {
NSLog(@"Error! %@",[error localizedDescription]);
}];
}
我实例化 feedList NSMutableArray 并在我的 viewDidLoad 方法中调用 getStream 方法
- (void)viewDidLoad
{
[super viewDidLoad];
feedList = [[NSMutableArray alloc] initWithObjects:@"zero", @"one", @"two", nil];
[self getStream];
}
编辑:
这是 NSURLConnection-block.m
#import "NSURLConnection-block.h"
@implementation NSURLConnection (block)
#pragma mark API
+ (void)asyncRequest:(NSURLRequest *)request success:(void(^)(NSData *,NSURLResponse *))successBlock_ failure:(void(^)(NSData *,NSError *))failureBlock_
{
[NSThread detachNewThreadSelector:@selector(backgroundSync:) toTarget:[NSURLConnection class]
withObject:[NSDictionary dictionaryWithObjectsAndKeys:
request,@"request",
successBlock_,@"success",
failureBlock_,@"failure",
nil]];
}
#pragma mark Private
+ (void)backgroundSync:(NSDictionary *)dictionary
{
//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
void(^success)(NSData *,NSURLResponse *) = [dictionary objectForKey:@"success"];
void(^failure)(NSData *,NSError *) = [dictionary objectForKey:@"failure"];
NSURLRequest *request = [dictionary objectForKey:@"request"];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(error)
{
failure(data,error);
}
else
{
success(data,response);
}
//[pool release];
}
@end
这是 NSURLConnection-block.h
#import <Foundation/Foundation.h>
@interface NSURLConnection (block)
#pragma mark Class API Extensions
+ (void)asyncRequest:(NSURLRequest *)request success:(void(^)(NSData *,NSURLResponse *))successBlock_ failure:(void(^)(NSData *,NSError *))failureBlock_;
@end
我希望有一个人可以帮助我。我真的很感激!:)