簡體   English   中英

如何檢查Xcode Asset Catalog中是否存在圖像?

[英]How to check if an image exists in Xcode Asset Catalog?

我通過HTTP獲取JSON數據,並希望使用自定義MKAnnotationView在MKMapView中顯示它們。 所以直到這里沒問題。

糟糕的是REST服務可能會返回我的.xcassets文件中沒有等效項的引腳類型。 有沒有辦法檢查應用程序的資產目錄中的條目,並避免這樣的消息:

CUICatalog:提供的資產名稱無效:NonExistingImage或無效比例因子:2.000000

當前代碼示例:

NSString * imageName = @"NonExistingImage";

if (imageName != nil) {
    // this line creates the above message
    UIImage * image = [UIImage imageNamed:imageName]; 

    // checking for image != nil, otherwise use default image
} else {
    // default image
}

我的解決方案:似乎你用一個空的NSString(或nil)調用imageNamed這個信息被記錄下來。 如果簡單地通過了圖像不存在時,所得的UIImage是零,並創建NO消息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM