2017-02-08 4 views
0

私はiOSで新しく、Image PickerからUITableViewでイメージを設定する際に問題が発生しています。Objective cでUITableViewにキャプチャイメージを追加する方法

私のコードは、私が直面しています問題は、それが画像

enter image description here

のように行に応じて設定され取得されていないということですcellforRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     cell.Photobtn.tag=indexPath.row; 
[cell.Photobtn addTarget:self action:@selector(btnphotoClick:) forControlEvents:UIControlEventTouchUpInside]; 
    cell.CaptureImage.image = [imageArray objectAtIndex:indexPath.row]; 
} 

でこの

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo 
{ 
    CGSize newSizeClient=CGSizeMake(200,200); // I am giving resolution 50*50 , you can change your need 
    UIGraphicsBeginImageContext(newSizeClient); 
    [image drawInRect:CGRectMake(0, 0, newSizeClient.width, newSizeClient.height)]; 
    UIImage* newImageClient = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    captureimg.image = newImageClient; 

    [imageArray replaceObjectAtIndex:index withObject:captureimg.image]; 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     [Audittable reloadData]; 
    }); 

    NSData *imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation((newImageClient), 0.5)]; 
    OCSSignString = [imgData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; 

    [picker dismissModalViewControllerAnimated:YES]; 

    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 30,40,40)]; 
    UIImage *wonImage = captureimg.image; 
    imageView.contentMode=UIViewContentModeCenter; 
    [imageView setImage:wonImage]; 

} 

のようなものです

私はtableviewcelに従って画像をキャプチャしていますl

-(void)btnphotoClick:(UIButton *)sender 
{ 
    AuditNextTableViewCell *cell = sender.superview.superview; 


    imageArray =[[NSMutableArray alloc]init]; 
    for (int i=0; i<idarray.count; i++) { 
     [imageArray addObject:[UIImage new]]; 
    } 

    index=sender.tag; 

    if (! [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 

     UIAlertView *deviceNotFoundAlert = [[UIAlertView alloc] initWithTitle:@"No Device" message:@"Camera is not available" 
                    delegate:nil 
                  cancelButtonTitle:@"Okay" 
                  otherButtonTitles:nil]; 
     [deviceNotFoundAlert show]; 
    } 
    else 
    { 
     UIImagePickerController *cameraPicker = [[UIImagePickerController alloc] init]; 
     cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
     cameraPicker.delegate =self; 
     [self presentViewController:cameraPicker animated:YES completion:nil]; 
    } 
} 

問題は私が直面していることに直面しています。前進に感謝します!

+0

ここではidArrayとは何ですか? – User511

+0

そしてなぜyuが配列オブジェクトを置き換えているのですか? – User511

+0

@ User511 idArrayはサーバーから送信されています。 – Muju

答えて

1

問題は、あなたのimageArrayUIImageオブジェクトを初期化するたびにある、あなたのボタンアクションです。ボタンアクションからこのコードを削除します。

imageArray = [[NSMutableArray alloc]init]; 
for (int i=0; i<idarray.count; i++) { 
    [imageArray addObject:[UIImage new]]; 
} 

あなたは、あなたのtableView初めてロードする際に空のUIImageオブジェクトに一度だけあなたのimageArrayを初期化する必要があります。

+0

はい私はクラッシュするあなたのコードを試してみます。 – Muju

+0

@Mujuコードを単純に削除したので、ボタンアクションからこのコードを削除して、tableViewを再ロードする場所や 'idarray'を設定した場所に配置する必要があることを伝えました。 –

+0

私はそれを行います。 – Muju

0
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo 
    { 
     BookingCell *cell=(BookingCell*)[self.tablebview cellForRowAtIndexPath:indexPath]; 
     cell.CaptureImage.image = image; 
    } 

    -(IBAction)buttonclick:(id)sender 
    { 
     CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView]; 
     NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition]; 
    } 
+0

新しい彼女は何ですか? – Muju

+0

ボタンの選択されたインデックスパス –

+0

は動作していますか? –

関連する問題