3

I have a UIImage that I want to display with TTPhotoViewController, but TTPhotoViewController does not take a UIImage as an argument. It does take a TTPhoto as an argument, so I'm wondering if there is a way to convert a UIImage to a TTPhoto or if there is any other way to get the TTPhotoViewController to display my UIImage other than setting the defaultImage, which didn't work too good.

Erik B
  • 40,889
  • 25
  • 119
  • 135

4 Answers4

7

I use a little hack to do it:

NSString *url = [[TTURLCache sharedCache] createUniqueTemporaryURL];    
[[TTURLCache sharedCache] storeImage:baseImage forURL:url force:YES];

PEPhotoViewController *album=[[[PEPhotoViewController alloc] initWithImageURL:url] autorelease];
elife
  • 153
  • 8
3

You need to create an object that conforms to the TTPhotoSource protocol, implementing the required methods. Then you need to populate that data source with objects that conform to the TTPhoto protocol.

You should then be able to set the photo source property on the TTPhotoViewController and Three20's magic should work.

In my own experience I've only used this framework with URLs to images and downloading them using Three20's TTModel framework. I'm not entirely sure how this affects loading images locally.

Jasarien
  • 58,279
  • 31
  • 157
  • 188
  • I kind of added Three20 to the project because I wanted a nice PhotoViewer. All the images are stored locally. Also I just want to display one image, at least for now. – Erik B Jun 21 '10 at 15:13
  • You can't really escape Three20's way of doing things. It's just the way its written. If you want to use the photo viewer, you have to create a photo source and populate it. If you want to just show a few images in a scroll view I'd suggest looking into the UIScrollView documentation and sample apps and cooking up your own simpler photo browser. Three20 as a whole is quite a monster, and besides its ongoing refactor, it's still quite difficult to get to grips with. – Jasarien Jun 21 '10 at 16:38
  • I asked this question long ago and I don't even have access to the source code anymore, but I think this is what I ended up doing, so I guess I should accept this as my answer. – Erik B Feb 11 '11 at 19:56
1

You can give local path to the library. Should be bandle:// or documents:// . Take a look at the TTCatalog example source.

Ariel
  • 2,430
  • 1
  • 17
  • 20
0

just set self.defaultImage to your image. It should work.

Saleh
  • 380
  • 3
  • 19