【问题标题】:Add image and text to tableview将图像和文本添加到 tableview
【发布时间】:2012-01-26 16:59:38
【问题描述】:

我尝试将一些从文本字段中获取的文本和从相册中获取的图像添加到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];

【问题讨论】:

  • 您能重新表述一下您的问题吗?这不是很清楚。自包含样本有助于理解问题。提前谢谢你。
  • 抱歉,您想做什么?您想在 UITableView 中显示文章数组中包含的项目吗?你想要一些建议吗?提前谢谢你。
  • 抱歉有人改变了我的问题
  • 尝试在您的问题下添加一些令人上瘾的解释。您可以尝试将您的问题分步进行。例如:1)创建文本和图像并将它们添加到单元格中 2)创建一个包含表格视图的视图控制器 3)将该控制器添加到选项卡栏控制器中。希望对您有所帮助。
  • 我尝试将文本文件中的文本和 imageview 中的图像(在 uiimageview 中我有用户从相机拍摄的照片)到 UITableViewCell

标签: iphone ios uitableview uibutton uitabbarcontroller


【解决方案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;
}

【讨论】:

    【解决方案2】:

    你要继承 UICell 类,例子太多了。只是像“自定义 UITableView”或“自定义 UITableViewCell”这样的 google smth。

    另外,Cocoa 中的单元格还有左图。

    【讨论】:

      【解决方案3】:

      添加自定义单元格以在表格视图中显示图像

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-12-23
        • 1970-01-01
        • 2016-04-06
        • 1970-01-01
        • 2018-05-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多