Я хочу добавить изображение на кнопку, которая находится на ячейке tableview, это мой код, все работает, но после выбора изображения, его не установлено или видно на imagebutton
, пожалуйста, помогите мне. .....Добавить изображение на background background background
в cellForRowAtIndexpath
метод
if(indexPath.row == 0)
{
cell.userInteractionEnabled = YES;
cell.textLabel.text [email protected]"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];
}
попробуйте перезагрузить ячейку следующим образом: [self.tableView reloadRowsAtIndexPaths: [NSArray arrayWithObjects: indexPathOfYourCell, nil] withRowAnimation : UITableViewRowAnimationNone]; – cyberlobe
Вы можете показать первое изображение (AFPFriendThumbnail.png) на кнопке .. или нет.? –