表视图与自定义单元格/图像和标签

时间:2015-04-27 11:37:18

标签: objective-c iphone xcode uitableview

如何用例如填充表格视图(自定义单元格)的最佳方法来自相机胶卷的选定图像和文本字段中的用户定义文本?以及如何保存它?

词典?阵列? ....?

2 个答案:

答案 0 :(得分:0)

您可以使用以下格式。

字典数组。 数组包含多个字典,每个字典包含您的数据,如图像引用和文本消息

这可能是存储数据的好格式

答案 1 :(得分:0)

在.h文件中创建图像属性和tableview出口。

@property(nonatomic, strong) UIIImage *photoImage;
@property(nonatomic, strong) IBOutlet UITableView *tableview;
在didFinishPickingMediaWithInfo中的.m文件中:方法:

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image;
    image = (UIImage *)
    [info valueForKey:UIImagePickerControllerOriginalImage];
    self.photoImage = image;
    [self.tableView reloadData]; //call reloadData method to load data with image
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    [picker dismissViewControllerAnimated:YES completion:nil];
}

in cellForRowAtIndexPath:method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   UITableViewCell *cell = [self.movieTable dequeueReusableCellWithIdentifier:@"cell"];
   cell.imageView.image = self.photoImage; 
   or use array and add image to array in didFinishPickingMediaWithInfo: and use the image

   cell.imageView.image = [self.photoArray objectAtIndex:0]; 

}

这会对你有所帮助:)。

相关问题