Add image and text to tableview

advertisements

I try to add some text taken from a textfield and an image taken from photo album to UITableViewCell.

In one UIViewController I have a UITextField and a UIImageView. This is the code I use to populate an array of products that I would present in cells of a UITableView.

Article *article1 = [[Article alloc] initWithTitle: @"First Text" Subtitle: @"Data&Time" Thumbnail: [UIImage imageNamed: @"image.png"]];
articles = [[NSMutableArray alloc] init];
[articles addObject:article1];


Do you want the cells to display the properties of your Article objects? Let's assume you only have one section and your UITableViewController already has a reference to an array of Articles called "articles".

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    Article *article = [articles objectAtIndex:indexPath.row];
    cell.textLabel.text = article.title;
    cell.detailTextLAbel.text = article.subtitle;
    cell.imageView.image = article.thumbnail;
    return cell;
}