所以我有一个自定义uitableviewcell
,使用iCarousel
加载另一个视图。那个观点失去了buttons
。我看不到按钮,我可以点击它们,但是当我这样做时有一个例外。我认为这是一个记忆问题。
这就是我创建视图的方式 -
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(OptionView *)view
{
if (view == nil)
{
view = [[[NSBundle mainBundle] loadNibNamed:@"OptionView" owner:view options:nil] lastObject];
}
NSDictionary* option = [self.options objectAtIndex:index];
view.imageUrl = option[@"ImageUrl"];
view.option = option[@"Option"];
view.currentPage = option[@"Page"];
view.page = view.currentPage;
view.postAs = self.postingAs;
[view init];
return view;
}
为什么我收到错误?
-(id)init{
self = [super init];
self.upVotesLabel.text = [NSString stringWithFormat:@"%i", self.upVotes];
self.downVotesLabel.text = [NSString stringWithFormat:@"%i",self.downVotes];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
NSString* photoUrl = [NSString stringWithFormat:@"%@",self.imageUrl];
self.optionImageView.image = [UIImage imageNamed:@"trending.png"];
dispatch_async(queue, ^{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString: photoUrl]];
UIImage *image = [UIImage imageWithData:data];
self.optionImageView.image = image;
});
return self;
}
答案 0 :(得分:0)
在末尾删除此行[view init],它会再次初始化视图。
答案 1 :(得分:0)
如果在nib中加载视图。在awakeFromNib
- (void)awakeFromNib
{
self.upVotesLabel.text = [NSString stringWithFormat:@"%i", self.upVotes];
self.downVotesLabel.text = [NSString stringWithFormat:@"%i",self.downVotes];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
NSString* photoUrl = [NSString stringWithFormat:@"%@",self.imageUrl];
self.optionImageView.image = [UIImage imageNamed:@"trending.png"];
dispatch_async(queue, ^{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString: photoUrl]];
UIImage *image = [UIImage imageWithData:data];
self.optionImageView.image = image;
});
}