尝试对在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)中的getStream方法和asyncRequest类方法
- (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
我希望有一个人可以帮助我。我真的很感激! :)
最佳答案
您是自己将feedList
合成为feedList
ivar吗?否则,请尝试使用_feedList
,这是默认的综合变量。
关于ios - 从^ block访问@property,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15978765/