Javascript 在我的原型单元格xcode中显示图像
下午好 我在原型细胞中显示图像时遇到问题。目前,我只能显示标签文本,我想知道如何显示图像 以下是当前流程的屏幕截图: 我有一个图像的URL,但目前仅显示为标签: 我想以图像的形式展示一下。要做到这一点,我必须做些什么 ViewController.mJavascript 在我的原型单元格xcode中显示图像,javascript,ios,xcode,Javascript,Ios,Xcode,下午好 我在原型细胞中显示图像时遇到问题。目前,我只能显示标签文本,我想知道如何显示图像 以下是当前流程的屏幕截图: 我有一个图像的URL,但目前仅显示为标签: 我想以图像的形式展示一下。要做到这一点,我必须做些什么 ViewController.m - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Retrieve ce
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Retrieve cell
NSString *cellIdentifier = @"BasicCell";
UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
// Get the location to be shown
Location *item = _feedItems[indexPath.row];
// Get references to labels of cell
myCell.textLabel.text = item.address;
return myCell;
}
提前感谢。在
返回myCell之前
设置单元格的图像属性。例如,如果您有一个名为“images”的图像数组对应于您的单元格,则可以执行以下操作:
myCell.imageView.image = images[indexPath.row]
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Retrieve cell
NSString *cellIdentifier = @"BasicCell";
MyCustomCell *customCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
// Get the location to be shown
Location *item = _feedItems[indexPath.row];
// Get references to labels of cell
customCell.customLabel.text = item.address;
customCell.customImageView.image = arrayOfImages[indexPath.row]
return customCell;
}
您还可以通过子类化UITableViewCell
并将tableview中原型单元的类设置为自己的子类来创建自己的原型单元。然后,您可以在原型单元中的任何位置添加自己的UIImageView
,并创建一个链接到自定义单元类的IBOutlet
。然后,您的方法可以如下所示:
myCell.imageView.image = images[indexPath.row]
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Retrieve cell
NSString *cellIdentifier = @"BasicCell";
MyCustomCell *customCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
// Get the location to be shown
Location *item = _feedItems[indexPath.row];
// Get references to labels of cell
customCell.customLabel.text = item.address;
customCell.customImageView.image = arrayOfImages[indexPath.row]
return customCell;
}
您可以使用
UITableView
的imageView
对象,而不是UITableView
的UILabel
对象。例如,替换:
myCell.textLabel.text = item.address;
与:
或者您可以通过添加
UIImageView
作为子视图来自定义图像视图。但您甚至没有尝试在此处添加图像。。。您可以将图像添加为子视图,也可以使用单元格的image属性。我已在我的MainstryBoard中添加了imageView。但在cellForRowAtIndexPath中,您仅设置单元格的文本标签属性。。。item.address
是图像的web url吗?是的,item.address是图像url路径。如何设置手机的图像属性?谢谢Lyndsey。图像url位于网站中,完整url路径。谢谢。我收到以下错误:/Users/Downloads/DatabaseTableViewApp 3/DatabaseTableViewApp/ViewController.m:92:83:不兼容的指针类型将“NSString*”发送到“NSURL*”类型的参数。谢谢。@JulienKP哦,如果您的地址格式为NSString,您必须将其更改为NSURL。我已经更新了我的答案。