2010-08-05 63 views
3

我有一個TTPhotoViewController子類很好地工作。我需要能夠提供將下載的圖像保存到用戶保存的照片目錄的選項。我有問題實際檢索UIImage對象。檢索TTPhotoViewController的UIImage

通過API瀏覽後,我看到TTPhoto(這是視圖控制器的屬性之一)實際上並不包含要使用的UIImage。但是,在API內有一個TTImageView類,它具有UIImage屬性。 TTPhotoView派生自TTImageView,在我的視圖控制器類中有一個名爲「PhotoStatusView」的視圖。但是,當我訪問這個時,我不會收到UIImage。

任何想法?

+0

同樣的問題對我而言,我無法得到一個滿意的答案查看。 我也需要一個解決方案。 thx – 2011-01-11 17:08:12

回答

1

檢查這個網站了add save to album functionality

下面是從網站的代碼:

_clickActionItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: 
         UIBarButtonSystemItemAction 
         //TTIMAGE(@"UIBarButtonReply.png") 
    target:self action:@selector(clickActionItem)]; 



    UIBarButtonItem* playButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: 
    UIBarButtonSystemItemPlay target:self action:@selector(playAction)] autorelease]; 
    playButton.tag = 1; 


    UIBarItem* space = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: 
    UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease]; 
    _toolbar = [[UIToolbar alloc] initWithFrame: 
    CGRectMake(0, screenFrame.size.height - TT_ROW_HEIGHT, 
       screenFrame.size.width, TT_ROW_HEIGHT)]; 
    _toolbar.barStyle = self.navigationBarStyle; 
    _toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth 
           | UIViewAutoresizingFlexibleTopMargin; 

    NSString *searchCaption = @"Photo from networked"; 
    NSRange range = [[_centerPhoto caption] rangeOfString:searchCaption]; 

    if (range.location == NSNotFound) { 
     _toolbar.items = [NSArray arrayWithObjects: 
    space, _previousButton, space, _nextButton, space,_clickActionItem, nil]; 
    [_innerView addSubview:_toolbar]; 
    }else{ 
     _toolbar.items = [NSArray arrayWithObjects: 
          space, _previousButton, space, _nextButton, space, nil, nil]; 
     [_innerView addSubview:_toolbar]; 

    } 

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
} 
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 

    if(6 == actionSheet.tag) 
    { 
     if(0 == buttonIndex)//save page 

     {   

      NSLog(@"photo: %@", [_centerPhoto URLForVersion:TTPhotoVersionLarge]); 


      NSURL *aUrl = [NSURL URLWithString:[_centerPhoto URLForVersion:TTPhotoVersionLarge]]; 
      NSData *data = [NSData dataWithContentsOfURL:aUrl]; 
      UIImage *img = [[UIImage alloc] initWithData:data]; 

      NSLog(@"photo:class %@", [img class]); 

      UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil); 
0

你應該嘗試使用:

UIImage *image = [[TTURLCache sharedCache] imageForURL:URL];