Iphone 我无法在EasyTableView委托方法中访问我的变量
我使用的是扩展UITableView。我遇到如下问题:Iphone 我无法在EasyTableView委托方法中访问我的变量,iphone,objective-c,uitableview,Iphone,Objective C,Uitableview,我使用的是扩展UITableView。我遇到如下问题: - (void)viewDidLoad { NSArray *array = [[NSArray alloc] initWithObjects:@"14.jpg",nil]; photos = array; [array release]; [photos objectAtIndex:0]; //this "photos" can be access } 但
- (void)viewDidLoad
{
NSArray *array = [[NSArray alloc] initWithObjects:@"14.jpg",nil];
photos = array;
[array release];
[photos objectAtIndex:0]; //this "photos" can be access
}
但是,当我尝试使用委派方法访问照片时:
- (void)easyTableView:(EasyTableView *)easyTableView setDataForView:(UIView *)view forIndexPath:(NSIndexPath *)indexPath {
NSInteger r = [indexPath row]; // r = 0
NSString *imagePath = [photos objectAtIndex:r]; //this line cause : reason: '-[CALayer objectAtIndex:]: unrecognized selector sent to instance
}
为什么访问照片的结果不同?如何修复它?使用照片作为属性
@property (nonatomic, retain) NSMutableArray* photos;
以及在实施中
@synthesize photos = photos;
现在可以在委派中访问它photos变量没有保留您分配给它的数组。当它被释放时,内存被重新用于指向CALayer对象。如果照片是保留属性,则应使用self.photos=array;做作业。如果它只是一个简单的变量,那么直接分配它,而不是使用数组。信息不够。照片是在哪里定义的?您是如何定义的?照片是如何定义的?看起来需要使用self.photos=array才能正确保留对象。