我想在tableview单元格上的按钮上添加图像,这是我的代码,一切正常,但是在拾取图像后,其未设置或不可见imagebutton
,请帮助我......
在cellForRowAtIndexpath
方法中
if(indexPath.row == 0)
{
cell.userInteractionEnabled = YES;
cell.textLabel.text =@"Your Profile Photo";
imageBtn = [[UIButton alloc]initWithFrame:CGRectMake(250, 5, 35, 35)];
[imageBtn setBackgroundImage:[UIImage imageNamed:@"AFPFriendThumbnail.png"] forState:UIControlStateNormal];
[imageBtn addTarget:self
action:@selector(myAction)
forControlEvents:UIControlEventTouchUpInside];
imageView.backgroundColor = [UIColor lightGrayColor];
[cell addSubview:imageBtn];
}
按钮动作
-(void)myAction
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
[imageBtn setImage:image forState:UIControlStateSelected];
imageBtn.backgroundColor = [UIColor redColor];
[tableView_ reloadData];
}
尝试一下 UIControlStateNormal
[imageBtn setImage:image forState: UIControlStateNormal];
但是我可以看到您在设置图像后重新加载tableView,这将替换 imageBtn
imageBtn = [[UIButton alloc]initWithFrame:CGRectMake(250, 5, 35, 35)]; // Creating a button every time.
它应该imageBtn
无需重新加载即可工作,因为您保留了对的引用,因此可以直接进行设置。尝试删除[tableView_ reloadData]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句