gpt4 book ai didi

ios - 如何在 Objective c 中将捕获图像添加到 UITableView

转载 作者:行者123 更新时间:2023-11-29 00:30:08 25 4
gpt4 key购买 nike

我是 iOS 新手,我遇到了关于从图像选择器在 UITableView 中设置图像的问题。

我的代码是这样的

- (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];

}

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

我面临的问题是它没有像图像中那样根据行进行设置

enter image description here

我正在根据tableviewcell抓图

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

我面临的问题是它已经过时了。提前致谢!

最佳答案

问题出在您的按钮操作中,您每次都使用空的 UIImage 对象初始化您的 imageArray。从您的按钮操作中删除此代码。

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

当您第一次加载您的 tableView 时,您只需使用空的 UIImage 对象初始化您的 imageArray 一次。

关于ios - 如何在 Objective c 中将捕获图像添加到 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42105983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com