3

私のアプリケーションでは、カスタマイズされたテーブルを使用しています。各セルには uibutton と uiimage があります。ボタンにタッチアップが発生した場合、uiimagepickercontroller メソッドを呼び出して、iphone ライブラリから画像を選択し、画像ビューに表示したいと考えています。私はそれを書きましたが、警告が表示されました...「customCell」はpresentmodalviewcontrollerのアニメーションに応答しない場合があります...ここで、customCellは私のメインクラスmyAppのサブクラスであり、カスタムセルのペン先の名前でもあります。誰でも問題を知っていますか???? ありがとう...

編集

- (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   
}  

これはカスタムセルクラスです..そしてviewControllerクラスは...

- (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;
 } 
4

2 に答える 2

6

UITableViewCellに応答しません-presentModalViewController:animated:

おそらく、CustomCell にビュー コントローラーへのポインターを与えてから、ビュー コントローラーを呼び出すことができます-presentModelViewController:animated:

カスタム セル クラスにインスタンス変数を追加します。

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

-tableView:cellForRowAtIndexPath:、新しい CustomCell を作成した後、次のプロパティを設定します。

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;
        }
    }
}

次に、CustomCell クラスで、次のように置き換えます。

[self presentModalViewController:picker animated:YES];

[self.viewController presentModalViewController:picker animated:YES];
于 2009-12-02T06:57:17.797 に答える
0

これはあなたの質問の答えにはなりませんがUIButton、セルに が必要な場合は、UI 設計が間違っている可能性があります。セル全体にアクションを実行させる方法を考えてみてください。そうでない場合は、開示ガジェットか何かを使用します。

于 2009-12-02T07:46:17.957 に答える