如何将本地图像与 WebService 数据结合使用

发布于 2024-11-18 04:01:31 字数 298 浏览 4 评论 0原文

我正在使用 SOAP WS 来获取数据。我在响应中得到了四个参数 - Topic_Name、Topic_Id、Topic_ImagePath 和 Topic_Details。现在,我在本地拥有主题的所有图像,其名称与我从特定主题_ID 的网络服务获得的名称相同。

我的问题是我想使用本地图像而不是使用 Topic_ImagePath 的图像,但数据必须来自 Web 服务。

我不想使用 if ..else 条件,因为我有超过 1000 个主题,任何人都可以解释我如何获取本地图像的路径并使用来自 Web 服务的数据显示它。

提前感谢。

I am Using SOAP WS for getting the Data. I got the four Parameters in Response - Topic_Name, Topic_Id, Topic_ImagePath and Topic_Details. Now I have All the Images of Topic Locally with the same name as i got from the web service for Particular Topic_ID.

My question is I want to use Local image instead using the Topic_ImagePath 's Image but the data Must Come From the Web Service.

I dont want to use if ..else condition because I have more than 1000 Topics, any one can explain how I get the Path of Local Image and Display it with the Data Comes From the Web Service..

Thanx in Advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

热鲨 2024-11-25 04:01:31

如果您本地已存储同名图像。然后,您可以从从服务器获取的图像路径中获取图像名称的子字符串,并将其显示在本地图像的 UIImageview 中。

If you have stored images with same name locally. Then you can substring of name of image from the imagepath you are getting from server and show it in UIImageview from the local images.

枫林﹌晚霞¤ 2024-11-25 04:01:31

使用诸如 Topic_ID_ImageName 之类的名称方案在本地存储图像。如果可用,则在本地搜索该图像,否则使用 Topic_ImagePath 的图像

Store images locally using name scheme something like Topic_ID_ImageName. Search for that Image locally if it is available else use Topic_ImagePath 's Image

£噩梦荏苒 2024-11-25 04:01:31

如果您可以从 Web 服务获取的字符串中获取图像名称,并且图像已添加到您的项目中,则可以使用 [UIImage imagenamed: @"imagename"] 来获取图像。

如果它存储在您的设备上并且您知道位置但它不是您项目的一部分,您可以使用以下代码:

NSString *imageName = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imagename]];
        if ([[NSFileManager defaultManager] fileExistsAtPath:imageName] == TRUE) {
            _storeImage = [[UIImage alloc] initWithContentsOfFile:imageName];
    }

If you can get the image name from the string you get from the webservice, and the image is added to your project you can use [UIImage imagenamed: @"imagename"] to get the image.

If it is stored on your device and you know the location but it is not part of your project you can use the following code:

NSString *imageName = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imagename]];
        if ([[NSFileManager defaultManager] fileExistsAtPath:imageName] == TRUE) {
            _storeImage = [[UIImage alloc] initWithContentsOfFile:imageName];
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文