1

I have implemented the following function:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UIImage *img = [UIImage imageNamed:@"persona.jpeg"];
    UIImageView *temp = [[UIImageView alloc] initWithImage:img]; 
    temp.frame = CGRectMake(-70, 10, 60, 40);

    UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, -5, 80, 60)];
    channelLabel.text = @"persona y";
    channelLabel.textAlignment = UITextAlignmentLeft;
    channelLabel.backgroundColor = [UIColor clearColor];

    UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 110, 60)];
    [tmpView insertSubview:temp atIndex:0];
    [tmpView insertSubview:channelLabel atIndex:1];

    return tmpView; 
}

and the result is the following:

Screen

I need to insert the image and text in a specific row, any idea how to do it?
Thank you very much for your help.

My idea is to fill an array of pictures and a description to fill the UIPickerView

  • You mean it like a UITableView? I don't understand exactly your problem. – Natan R. Sep 03 '12 at 16:37
  • the image and text are replicated in all the rows I need to insert the image and text in a specific row because then I load the picker view with different images and then the description of the image – Andres Salazar Lopez Sep 03 '12 at 17:01

1 Answers1

7

Try to get your data as Array of NSDictionary.

Dictionary structure : {Image:<imageName>, LabelText:<labelText>}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view
{
    NSDictionary *dict =  [datasourceArray objectAtIndex:row];
    UIImage *img = [UIImage imageNamed:[dict valueForKey:@"Image"]]; // get image path from the dictionary
    UIImageView *temp = [[UIImageView alloc] initWithImage:img]; 
    temp.frame = CGRectMake(-70, 10, 60, 40);

    UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, -5, 80, 60)];
    channelLabel.text = [dict valueForKey:@"LabelText"];
    channelLabel.textAlignment = UITextAlignmentLeft;
    channelLabel.backgroundColor = [UIColor clearColor];

    UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 110, 60)];
    [tmpView insertSubview:temp atIndex:0];
    [tmpView insertSubview:channelLabel atIndex:1];

    return tmpView;
}
Shrey
  • 1,959
  • 2
  • 21
  • 44
  • iShrey should I use the same logic to implement a chat app with text, images and location data types? Thinking of detect data type of the message in a "messages array of dictionaries" like {Image:, LabelText:, Location:} configuring my tableView cells according to each data type. – Marcos Reboucas Aug 27 '13 at 23:33