gpt4 book ai didi

ios - 使用组合字符串从 url 快速加载图像

转载 作者:可可西里 更新时间:2023-11-01 02:18:53 25 4
gpt4 key购买 nike

我有包含 detailTitle、detailDesc 字符串的工作代码,但我的 detailImage 字符串没有显示我的 UIImage。我的代码在下面。

ViewController 这里是我的字符串到 DetailView Controller

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let subcatVC = self.storyboard?.instantiateViewControllerWithIdentifier("Detail") as! DetailViewController
subcatVC.detailTitle = self.arrayCategory[indexPath.row][API_PARAM_CAT_NAME] as! String
subcatVC.detailDesc = self.arrayCategory[indexPath.row][API_PARAM_DESC_NAME] as! String
subcatVC.detailImage = self.arrayCategory[indexPath.row][API_PARAM_CAT_IMAGE] as! String
_ = UINavigationController(rootViewController: subcatVC)
self.navigationController?.pushViewController(subcatVC, animated: false)

NSLog("%@", self.arrayCategory[indexPath.row][API_PARAM_CAT_IMAGE] as! String);

}

细节 View Controller

class DetailViewController: UIViewController {

var detailTitle:String?
var detailDesc:String?
var detailImage:String?




@IBOutlet weak var textim: UILabel!
@IBOutlet weak var textbig: UITextView!
@IBOutlet weak var imagetbig: UIImageView!


override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

override func viewDidLoad() {
super.viewDidLoad()

textbig.text = detailDesc
textim.text = detailTitle


if let url = detailImage {
load_image(url)
}


func load_image(urlString:String)
{




let imgURL: NSURL = NSURL(string: urlString)!
let request: NSURLRequest = NSURLRequest(URL: imgURL)

let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request){
(data, response, error) -> Void in

if (error == nil && data != nil)
{
func display_image()
{
self.imagetbig.image = UIImage(data: data!)

}

dispatch_async(dispatch_get_main_queue(), display_image)
}

}

task.resume()
}

我需要;

顶级代码运行良好但不显示图像,因此我需要为我的完整图像 url 组合字符串。

NSLog("%@",detailImage)  Output =  23423434.jpg

我的基本 url 字符串:

let URL_API_HOST2:String = "http://www.bla.com/MyImages/"

我想结合 detailImage 和 URL_API_HOST2

我想显示组合的 detailImage 字符串;

http://www.bla.com/MyImages/23423434.jpg

我需要你的帮助。TY

最佳答案

我不确定你的基本 url 字符串在哪里声明,但我不明白你为什么不能简单地连接字符串:

例如,代替:

if let url = detailImage {
load_image(url)
}

你可以做到

if let url = detailImage {
load_image(URL_API_HOST2 + url)
}

关于ios - 使用组合字符串从 url 快速加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32957720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com