I'm developing an app in which the user can enter products and information on those products. All information on a products gets entered in a custom UITableViewCell. I also want to allow the user to add an image of products. To do that, I need to show a popover view containing UIImagePickerController. when I do that, Xcode giver me this error:
Popovers cannot be presented from a view which does not have a window.
When the user taps the button to add an(called addImage
) image, my custom cell triggers this action inside my TableView:
- (void) addImage
{
CustomCell *customcell = [[CustomCell alloc] init];
itemImagePicker = [[UIImagePickerController alloc] init];
itemImagePicker.delegate = self;
itemImagePicker.sourceType= UIImagePickerControllerSourceTypePhotoLibrary;
itemImagePopover = [[UIPopoverController alloc] initWithContentViewController:itemImagePicker];
[itemImagePopover presentPopoverFromRect:customCell.addImage.bounds inView:self.tableView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
my cellForRowAtIndexPath looks like:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CustomCellIdentifier = @"CustomCellIdentifier ";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell"
owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[CustomCell class]])
cell = (CustomCell *)oneObject;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSUInteger *row = [indexPath row];
Model *model = self.products[indexPath.row];
cell.itemName.text = model.itemName;
cell.itemDescription.text = model.itemDescription;
cell.itemPrice.text = model.itemPrice;
cell.itemPrice.delegate = self;
cell.itemName.delegate = self;
cell.itemDescription.delegate = self;
NSLog(@"%@", cell.itemPrice);
return cell;
}
("model" is a custom class. each instance of that class represents one product. everyctime the user adds a row to the tableview, one instance of this class gets added to an array.)
I have been searching SO and google all day, and I haven't found any solution on how this works with a custom cell, only on how it works in the didSelectRowAtIndexPath and when a disclosure button is touched.
so my put is shortly: How do I properly show a popover view when A button inside a custom cell is tapped?
Thank you in advance, any help would be much appreciated.