Question

In my application, i'm using a customised table. Each cell have an uibutton and uiimage. When a touch up accurs at the button, i want to call the uiimagepickercontroller method to select a picture from the iphone library and display it in the image view. I've written it but getting a warning... 'customCell' may not respond to presentmodalviewcontroller animated... here customCell is the subclass of my main class, myApp, also the name of the nib of the custom cell. Anyone knows the issue???? Thanks...

EDIT

- (IBAction)selectExistingPicture1 { 
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self; 
        picker.allowsImageEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:picker animated:YES];
        [picker release];
    } 
    else { 
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library" message:@"Device does not support a photo library" delegate:nil cancelButtonTitle:@"Drat!" otherButtonTitles:nil]; 
        [alert show]; 
        [alert release]; 
    } 
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {    
    CGSize newSize = CGSizeMake(80, 80);
    UIGraphicsBeginImageContext( newSize );
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    imageView.image = newImage;

    [picker dismissModalViewControllerAnimated:YES]; //warning shown here   
}  

This is the custom cell class.. and the viewController class has...

- (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:nil options:nil];
         for (id currentObject in nib){
             if ([currentObject isKindOfClass:[CustomCell class]]){
                 cell = (CustomCell *)currentObject; break;
             }
         }
     }

     NSUInteger s= indexPath.section;
     //[cell setText:[NSString stringWithFormat:@"I am cell %d", indexPath.row]];

     NSUInteger r = indexPath.row;
      cell.imageView.image = nil;
     for (s;s==0;s++)
     for(r;r==0;r++)
     {       
          UIImage *img=imageView.image;
         cell.imageView.image = img;
         }
     return cell;
 } 
Was it helpful?

Solution

UITableViewCell doesn't respond to -presentModalViewController:animated:.

You could probably give your CustomCell a pointer to your view controller, and then call -presentModelViewController:animated: on the view controller.

Add an instance variable to your custom cell class:

@interface CustomCell : UITableViewCell {
    UIViewController *viewController;
}
@property (nonatomic, assign) UIViewController *viewController;
@end

In -tableView:cellForRowAtIndexPath:, after you create a new CustomCell, set the property:

if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];
    for (id currentObject in nib){
        if ([currentObject isKindOfClass:[CustomCell class]]){
            cell = (CustomCell *)currentObject;
            cell.viewController = self; // <-- add this
            break;
        }
    }
}

Then, in your CustomCell class, replace

[self presentModalViewController:picker animated:YES];

with

[self.viewController presentModalViewController:picker animated:YES];

OTHER TIPS

This won't answer your question, but if you have to have a UIButton in a cell, you're probably going about your UI design wrong. Try to think of a way to have the entire cell perform the action, of if not that, use a disclosure gadget or something.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top