【发布时间】:2023-03-23 19:08:01
【问题描述】:
我正在创建一个名为 S3ObjectController (S3OC) 的类的实例,该类具有一个方法和四个委托方法。我创建了我的 S3OC 的一个实例,从 S3OC 类调用一个实例方法(我知道它是从 NSLog 语句触发的),但是在 S3OC 类中没有调用任何关联的委托方法。我在方法中将委托设置为 self,并在 .h 标头中正确声明了委托。
想法?为了清楚起见,我认为应该调用下面的 .m 文件中的 (void)request 方法不是。我收到 EXC BAD ACCESS 错误。 self 会被 ARC 释放吗?
S3OC类的整个.m文件如下:
#import "S3ObjectController.h"
@implementation S3ObjectController
@synthesize string;
@synthesize s3GOR, s3Client;
-(void)method
{
NSLog(@"Method Called");
s3Client = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
s3GOR = [[S3GetObjectRequest alloc]initWithKey:string withBucket:[Constants pictureBucket]];
[s3GOR setDelegate:self];
[s3Client getObject:s3GOR];
NSLog(@"Method Finished");
}
-(void)request:(AmazonServiceRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Error %@",error);
}
-(void)request:(AmazonServiceRequest *)request didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"Response Key %@", response);
}
-(void)request:(AmazonServiceRequest *)request didReceiveData:(NSData *)data
{
NSLog(@"ObjectRequestKey = %@",request);
}
-(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response
{
NSLog(@"Final Delegate Method");
}
这是标题:"
@interface S3ObjectController : NSObject <AmazonServiceRequestDelegate>{
NSMutableData *responseData;
NSString *string;
AmazonS3Client *s3Client;
S3GetObjectRequest *s3GOR;
}
-(void)method;
@property (nonatomic, strong) NSString *string;
@property (nonatomic, strong) S3GetObjectRequest *s3GOR;
@property (nonatomic, strong) AmazonS3Client *s3Client;
@end
最后,这是我在另一个类中调用该方法的方式:
for (NSString *name in nameArray){
@try {
S3ObjectController *localS3 = [[S3ObjectController alloc]init];
localS3.string = name;
[localS3 method];
NSLog(@"called");
}
【问题讨论】:
-
你能贴出这门课的标题吗?
-
AmazonServiceRequestDelegate已经声明了那些did...方法,因此在您的标头中具有相同的方法定义是多余的。尝试删除这些,看看是否能解决您的问题。 -
为什么人们会降级我的问题?我不明白。
-
@Eric - This 可能与它有关...
-
如果人们愿意跳过该线程,我仍然可以真正使用这个问题的帮助。
标签: iphone delegates amazon-s3 subclass