키 포인트는 NSBundle.MainBundle.PathForResource를 호출하여
결과가 null이면 리소스가 존재하지 않는 것이고,
결과가 어떤 문자열이면 그 리소스가 존재하는 것이다.
일단 아래에 필자의 기준에서 사용하기 쉽게 구현한 메서드 하나를 붙여넣었다.
리팩토링할 여지를 많이 가지고 있는 메서드이므로 여러분에게 재미를 양보하였다.
public bool ExistsBundleResource(string relativePath, string fileNameOnly, string extension)
{
string resourceName = Path.Combine (relativePath, fileNameOnly);
var resourcePath = NSBundle.MainBundle.PathForResource (resourceName, extension);
return resourcePath != null;
}
사용 예: MyImage/abcd.png, Resources/MyImage/abcd.png의 존재유무를 확인하는 경우?
if (ExistsBundleResource("MyImage", "abcd", "png")) {
...
}
'Xamarin' 카테고리의 다른 글
| Xamarin 프로젝트 비주얼스튜디오에서 nuget 패키지 업데이트 오류나던 날 (0) | 2015.01.28 |
|---|---|
| iOS 앱 64-bit 의무지원과 Xamarin (2) | 2015.01.12 |
| 마이크로소프트 MVP ComCamp 2015 세미나 소식! (1월 31일) (0) | 2015.01.07 |
| Xamarin.Forms (PCL) 프로젝트 생성 중 에러 (0) | 2014.12.21 |
| 요세미티(Yosemite) 업그레이드 후 스토리보드 오류 해결방법 (0) | 2014.10.26 |
| Xamarin Evolve 2014 소식 (0) | 2014.04.11 |
| Xamarin.Android 프로젝트 속성 변경하려다가 오류(0x8000FFFF)를 만났을 때 (0) | 2014.01.27 |