将图像和文本添加到tableview

时间:2012-01-26 16:59:38

标签: iphone ios uitableview uibutton uitabbarcontroller

我尝试将从文本字段中获取的一些文本和从相册中拍摄的图像添加到UITableViewCell

在一个UIViewController中,我有一个UITextField和一个UIImageView。这是我用来的代码 填充我将在UITableView的单元格中显示的一系列产品。

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

3 个答案:

答案 0 :(得分:1)

您希望单元格显示文章对象的属性吗?假设您只有一个部分,并且您的UITableViewController已经引用了一个名为“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;
}

答案 1 :(得分:0)

你必须继承UICell类,有太多的例子。只需google smth就像“自定义UITableView”或“自定义UITableViewCell”。

此外,Cocoa还有单元格左侧图像。

答案 2 :(得分:0)

添加自定义单元格以将图像显示到表格视图

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       static NSString *CellIdentifier = @"MoreDetailCell";
    MoreDetailCell *cell = (MoreDetailCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {  
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MoreDetailCell" owner:self options:nil];
        for (id currentObject in topLevelObjects){
            if ([currentObject isKindOfClass:[UITableViewCell class]]){
                cell =  (MoreDetailCell *)currentObject;
                break;




            }
        }
    }
      cell.compImage.image = [UIImage imageNamed:@"Placeholder.png"];
      cell.yourtexfieldname.text  = @"ABC";
}
相关问题