当前位置: 首页 > 知识库问答 >
问题:

tableview图像显示不正确-iOS 8 iPhone应用程序目标C

荀辰钊
2023-03-14

我正在创建一个带有两个nsarray的简单tableView。第一个数组包含标题,第二个数组包含图像名称。一切正常。但是行分隔符在tableview中的图像后会显示一些空格(参见第一个屏幕截图),而它应该显示为没有空格(如第二个屏幕截图)。

第一张截图

第二张截图

我尝试了不同的方法,但遇到了相同的问题(在iOS8设备上测试)。

我做错了什么?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

// Return the number of rows in the section.
return [dataSourceArray count];
}


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

// "Cell" is the default cell identifier in a new Master-Detail Project
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}


  cell.textLabel.text = [dataSourceArray objectAtIndex:indexPath.row];

//get UIImage image Names from imageArray
cell.imageView.image=[UIImage imageNamed:[imageArray objectAtIndex:indexPath.row]];



return cell;
}

共有2个答案

慕容成文
2023-03-14

尽量使用字典

NSMutableArray *item;

- (void)viewDidLoad {
    [super viewDidLoad];

 self.item = [NSMutableArray array];

NSDictionary *item1 =  @{@"dicNameItem":@"NameItem",@"dicImageItem":@"ImageItem"};
[self.arrayScreen addObject:item1];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.arrayScreen count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellScreen" forIndexPath:indexPath];

    NSDictionary *dicName = [self.arrayScreen objectAtIndex:indexPath.row];
    cell.textLabel.text = [dicName objectForKey:@"dicNameItem"];
    cell.imageView.image  = [UIImage imageNamed:[dicName objectForKey:@"dicImageItem"]];

    return cell;

}
洪高阳
2023-03-14

我看不到你的形象。。可能您没有使用约束,或者您的单元格很小,您需要设置单元格的高度以查看图像。

 类似资料:
  • 我尝试了一切,但图像不会显示,我试图缩小图像,但没有用,我试图改变路径,我试图更改图像的位置,但没有帮助,我试图在互联网上搜索,但什么都没有。 我看到的只是空白的图形用户界面,没有文本和图像。如果你能帮我,你会帮我一个大忙。 代码如下:

  • 我试图检查通过cv2.imread()实际读取的数据,但每当我这样做时,我得到的是一个全灰色屏幕。我应该得到彩虹的图像。

  • 启动图标在安装OS8.0/8.1奥利奥的设备上显示不佳。我在奥利奥8.0/8.1中没有显示像这里一样的启动程序图标,但结果是: 有人能帮忙吗?

  • 请告诉我OpenLayers中的图标如何使用svg?svg应该有什么结构? 我们在使用svg时遇到了几个问题,并准备了一个示例: > 使用“颜色”属性(以绿色微笑和红色微笑为例)无法正确更改图像的颜色 如果删除指向标准“xmlns=”http://www.w3.org/2000/svg“的链接(例如黄色微笑),则不会显示图像。为什么它不起作用? 感谢您的回答!

  • 我有jframe与2 jboard。我有一些组件在第一个jboard和第二个按钮。当我在第一个面板上点击jbuton(调用方法删除所有)它删除所有组件(我调用方法重新验证(),重新绘制())在该jboard然后我显示第二个面板与组件。长话短说,我删除第一个jboard显示第二个,第二个显示第一个jframe,...在jboard之间切换工作正常,当我切换回第一个jboard光标时,按钮指针类型不显

  • 问题内容: 我想以特定尺寸在Android应用程序中显示图片。我该怎么做?请指导我?还有一件事,我想从SD卡中获得该图像。所以请帮帮我。 提前致谢。 问题答案: 首先,您需要创建一个imageview。 创建布局参数以在布局上添加imageview 然后获取您的图像路径 在ImageView上设置图像 获取您要添加的布局 将视图添加到布局