Search code examples
objective-cioscocoa-touchuitableviewuidocumentinteraction

Change UIDocument Interaction Icons


Possible Duplicate:
Change UIDocumentInteractionController Icons

I currently have a UITableView in my app that uses the UIDocumentInteractionController to show a default image for a certain file type: enter image description here

I was wondering if i have a place holder lets say for any image file type can i have that show instead of the default one? This is what i would like the default image placeholder to be: enter image description here

Is this possible and how would i implement this i read about using the .plist but i had no success.


Solution

  • The UTI property of UIDocumentInteractionController gives you the uniform type identifier for a file, see Uniform Type Identifier Concepts. For example, "public.tiff" for TIFF files, "public.jpeg" for JPEG files and "com.apple.quicktime-movie" for QuickTime Movies.

    Uniform type identifiers are declared in a conformance hierarchy. TIFF and JPEG files are both images, and in the UTI concept this is expressed by the fact that both "public.tiff" and "public.jpeg" conform to "public.image".

    This being said, you could do the following to display your own icon for all image file types.

    • Add that icon to your app resources, for example "myimageicon.png".

    • To choose an icon for a file, check if the UTI of that file conforms to "public.image" and use your icon in that case. Otherwise use a default icon.

      // Assuming that self.docInteractionController is already set up ...
      if (UTTypeConformsTo((CFStringRef)self.docInteractionController.UTI, kUTTypeImage)) {
          cell.imageView.image = [UIImage imageNamed:@"myimageicon.png"];
      } else {
          cell.imageView.image = docInteractionController.icons.lastObject;
      }
      

    You have to import <MobileCoreServices/MobileCoreServices.h> and add the MobileCoreServices.framework to make this compile.