菜鸟教程小白 发表于 2022-12-11 18:22:21

ios - 如何将图像添加到uitableviewcell


                                            <p><p>抱歉,这是一个新问题,但我搜索了一整天仍然找不到答案。当我运行该应用程序时,它仅显示带有标签和计数的行,但图像未显示在表格 View 单元格上。</p>

<pre><code>#import &#34;ViewController.h&#34;

@interface ViewController () &lt;UITableViewDataSource,    UITableViewDelegate&gt; {
NSMutableArray * imageNameArray;
//__weak IBOutlet UIImageView *cell;
__weak IBOutlet UITableView *Table;
}

@end

@implementation ViewController

- (void)viewDidLoad {
;
// Do any additional setup after loading the view, typically from a   nib.
;


}



-(void) arraySetup {
imageNameArray = ];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section {
return imageNameArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellId = @&#34;cell&#34;;
UITableViewCell *cell = ;
//cell.imageView.image =];

if (cell == nil) {
    cell = [   initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}


cell.textLabel.text = imageNameArray ;
cell.detailTextLabel.text = ;

UIImageView *imv = [initWithFrame:CGRectMake(10,5, 50, 25)];
imv.image=;
;
cell.imageView.image = imv.image;

return cell;
</code></pre>

<p>}</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这里有一些非常基本的代码供您学习:
我正在使用基本类 <code>UITableViewCell</code></p>

<pre><code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = ;
    cell.textLabel.text = @&#34;Your table row text&#34;;
    cell.imageView.image = ;// Here you specify your image
    cell.detailTextLabel.text = @&#34;Your descriptive text&#34;;
    return cell;
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何将图像添加到uitableviewcell,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/45317095/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/45317095/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何将图像添加到uitableviewcell