2011-04-29 2 views
0

저는 새로운 iPhone 응용 프로그램 개발자입니다. 사진 갤러리와 같은 하나의 응용 프로그램을 만들어야합니다. 내 문제는 사진 앨범에 이미지를 저장하는 방법입니다.Three20 이미지를 저장 하시겠습니까? (닫기)

나는 내 프로젝트를 빌드 할 수있어 아무런 오류가 없다. 내 시뮬레이터가 프로젝트를 실행할 수있다.

하지만 내가 추가 한 내용은 볼 수 없습니다. 희망은 나를 도울 수 있습니다. 감사합니다.

여기 내 코드.

Three20PhotoDemoAppDelegate.h

#import <UIKit/UIKit.h> 

@interface Three20PhotoDemoAppDelegate : NSObject <UIApplicationDelegate> { 
    UIWindow *window; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 

@end 

Three20PhotoDemoAppDelegate.m

#import "Three20PhotoDemoAppDelegate.h" 
#import "AlbumController.h" 
#import <Three20/Three20.h> 

@implementation Three20PhotoDemoAppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    // Override point for customization after application launch 
    TTNavigator* navigator = [TTNavigator navigator]; 
    TTURLMap* map = navigator.URLMap; 
    [map from:@"demo://album" toViewController: [AlbumController class]]; 

    [navigator openURLAction:[TTURLAction actionWithURLPath:@"demo://album"]]; 
    return YES; 
} 

- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)URL { 
    [[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:URL.absoluteString]]; 
    return YES; 
} 

- (void)dealloc { 
    [super dealloc]; 
} 
@end 

PhotoSource.h

#import <Three20/Three20.h> 
#import <Three20/Three20+Additions.h> 
typedef enum { 
    PhotoSourceNormal = 0, 
    PhotoSourceDelayed = 1, 
    PhotoSourceVariableCount = 2, 
    PhotoSourceLoadError = 4, 
} PhotoSourceType; 

@interface PhotoSource : TTURLRequestModel <TTPhotoSource> { 
    PhotoSourceType _type; 
    NSString* _title; 
    NSMutableArray* _photos; 
    NSArray* _tempPhotos; 
    NSTimer* _fakeLoadTimer; 
} 

- (id)initWithType:(PhotoSourceType)type title:(NSString*)title 
      photos:(NSArray*)photos photos2:(NSArray*)photos2; 

@end 

PhotoSource.m

수입 "PhotoSource.h"

@implementation PhotoSource 
@synthesize title = _title; 

- (void)fakeLoadReady { 
    _fakeLoadTimer = nil; 

    if (_type & PhotoSourceLoadError) { 
     [_delegates makeObjectsPerformSelector: @selector(model:didFailLoadWithError:) 
            withObject: self 
            withObject: nil]; 
    } else { 
     NSMutableArray* newPhotos = [NSMutableArray array]; 

     for (int i = 0; i < _photos.count; ++i) { 
      id<TTPhoto> photo = [_photos objectAtIndex:i]; 
      if ((NSNull*)photo != [NSNull null]) { 
       [newPhotos addObject:photo]; 
      } 
     } 

     [newPhotos addObjectsFromArray:_tempPhotos]; 
     TT_RELEASE_SAFELY(_tempPhotos); 

     [_photos release]; 
     _photos = [newPhotos retain]; 

     for (int i = 0; i < _photos.count; ++i) { 
      id<TTPhoto> photo = [_photos objectAtIndex:i]; 
      if ((NSNull*)photo != [NSNull null]) { 
       photo.photoSource = self; 
       photo.index = i; 
      } 
     } 

     [_delegates makeObjectsPerformSelector:@selector(modelDidFinishLoad:) withObject:self]; 
    } 
} 

- (id)initWithType:(PhotoSourceType)type title:(NSString*)title photos:(NSArray*)photos 
      photos2:(NSArray*)photos2 { 
    if (self = [super init]) { 
     _type = type; 
     _title = [title copy]; 
     _photos = photos2 ? [photos mutableCopy] : [[NSMutableArray alloc] init]; 
     _tempPhotos = photos2 ? [photos2 retain] : [photos retain]; 
     _fakeLoadTimer = nil; 

     for (int i = 0; i < _photos.count; ++i) { 
      id<TTPhoto> photo = [_photos objectAtIndex:i]; 
      if ((NSNull*)photo != [NSNull null]) { 
       photo.photoSource = self; 
       photo.index = i; 
      } 
     } 

     if (!(_type & PhotoSourceDelayed || photos2)) { 
      [self performSelector:@selector(fakeLoadReady)]; 
     } 
    } 
    return self; 
} 

- (id)init { 
    return [self initWithType:PhotoSourceNormal title:nil photos:nil photos2:nil]; 
} 

- (void)dealloc { 
    [_fakeLoadTimer invalidate]; 
    TT_RELEASE_SAFELY(_photos); 
    TT_RELEASE_SAFELY(_tempPhotos); 
    TT_RELEASE_SAFELY(_title); 
    [super dealloc]; 




} 





- (BOOL)isLoading { 
    return !!_fakeLoadTimer; 
} 

- (BOOL)isLoaded { 
    return !!_photos; 
} 

- (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more { 
    if (cachePolicy & TTURLRequestCachePolicyNetwork) { 
     [_delegates makeObjectsPerformSelector:@selector(modelDidStartLoad:) withObject:self]; 

     TT_RELEASE_SAFELY(_photos); 
     _fakeLoadTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self 
                 selector:@selector(fakeLoadReady) userInfo:nil repeats:NO]; 
    } 
} 

- (void)cancel { 
    [_fakeLoadTimer invalidate]; 
    _fakeLoadTimer = nil; 
} 

- (NSInteger)numberOfPhotos { 
    if (_tempPhotos) { 
     return _photos.count + (_type & PhotoSourceVariableCount ? 0 : _tempPhotos.count); 
    } else { 
     return _photos.count; 
    } 
} 

- (NSInteger)maxPhotoIndex { 
    return _photos.count-1; 
} 

- (id<TTPhoto>)photoAtIndex:(NSInteger)photoIndex { 
    if (photoIndex < _photos.count) { 
     id photo = [_photos objectAtIndex:photoIndex]; 
     if (photo == [NSNull null]) { 
      return nil; 
     } else { 
      return photo; 
     } 
    } else { 
     return nil; 
    } 
} 


@end 

Photo.h

#import <Three20/Three20.h> 

@interface Photo : NSObject <TTPhoto> { 
    id<TTPhotoSource> _photoSource; 
    NSString* _thumbURL; 
    NSString* _smallURL; 
    NSString* _URL; 
    CGSize _size; 
    NSInteger _index; 
    NSString* _caption; 
} 

- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size; 

- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size 
      caption:(NSString*)caption; 

@end 

Photo.m

#import "Photo.h" 
@implementation Photo 
@synthesize photoSource = _photoSource, size = _size, index = _index, caption = _caption; 

- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size { 
    return [self initWithURL:URL smallURL:smallURL size:size caption:nil]; 
} 

- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size 
      caption:(NSString*)caption { 
    if (self = [super init]) { 
     _photoSource = nil; 
     _URL = [URL copy]; 
     _smallURL = [smallURL copy]; 
     _thumbURL = [smallURL copy]; 
     _size = size; 
     _caption; 
     _index = NSIntegerMax; 
    } 
    return self; 
} 

- (void)dealloc { 
    TT_RELEASE_SAFELY(_URL); 
    TT_RELEASE_SAFELY(_smallURL); 
    TT_RELEASE_SAFELY(_thumbURL); 
    TT_RELEASE_SAFELY(_caption); 
    [super dealloc]; 


} 
- (void)viewDidLoad { 


} 


- (NSString*)URLForVersion:(TTPhotoVersion)version { 
    if (version == TTPhotoVersionLarge) { 
     return _URL; 
    } else if (version == TTPhotoVersionMedium) { 
     return _URL; 
    } else if (version == TTPhotoVersionSmall) { 
     return _smallURL; 
    } else if (version == TTPhotoVersionThumbnail) { 
     return _thumbURL; 
    } else { 
     return nil; 
    } 
} 

@end 

AlbumController.h

#import <Three20/Three20.h> 

@interface AlbumController : TTPhotoViewController <UIActionSheetDelegate>{ 
    NSArray *images; 
    UIBarButtonItem *_clickActionItem; 
    UIToolbar *_toolbar; 
} 
@property (nonatomic, retain) NSArray *images; 
@property (nonatomic, retain) UIBarButtonItem *_clickActionItem; 
@property (nonatomic, retain) UIToolbar *_toolbar; 
@end 

AlbumController.m

당신이 필요로하는 모든이 사진 앨범에 이미지를 저장하는 경우 0
#import "AlbumController.h" 
#import "PhotoSource.h" 
#import "Photo.h" 
@implementation AlbumController 
@synthesize images; 
- (void)loadView { 
    CGRect screenFrame = [UIScreen mainScreen].bounds; 
    self.view = [[[UIView alloc] initWithFrame:screenFrame] 
       autorelease]; 
    CGRect innerFrame = CGRectMake(0, 0, 
            screenFrame.size.width, 
            screenFrame.size.height); 
    _innerView = [[UIView alloc] initWithFrame:innerFrame]; 
    _innerView.autoresizingMask = UIViewAutoresizingFlexibleWidth| 
    UIViewAutoresizingFlexibleHeight; 
    [self.view addSubview:_innerView]; 
    _scrollView = [[TTScrollView alloc] initWithFrame:screenFrame]; 
    _scrollView.delegate = self; 
    _scrollView.dataSource = self; 
    _scrollView.backgroundColor = [UIColor blackColor]; 
    _scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth| 
    UIViewAutoresizingFlexibleHeight; 
    [_innerView addSubview:_scrollView]; 
    UIBarButtonItem *_actionButton = [[UIBarButtonItem alloc] initWithImage: 
        TTIMAGE(@"bundle://Three20.bundle/images/imageAction.png") 
                style:UIBarButtonItemStylePlain target:self action:@selector 
        (popupActionSheet)]; 
    _nextButton = [[UIBarButtonItem alloc] initWithImage: 
        TTIMAGE(@"bundle://Three20.bundle/images/nextIcon.png") 
                style:UIBarButtonItemStylePlain target:self action:@selector 
        (nextAction)]; 
    _previousButton = [[UIBarButtonItem alloc] initWithImage: 
         TTIMAGE(@"bundle://Three20.bundle/images/previousIcon.png") 
                 style:UIBarButtonItemStylePlain target:self action:@selector 
         (previousAction)]; 
    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; 
    _toolbar.items = [NSArray arrayWithObjects: 
         _actionButton, space, _previousButton, space, 
         _nextButton, space, nil]; 
    [_innerView addSubview:_toolbar]; 
} 

//(Just to add an action sheet) 
//At the bottom of that codefile -- I added: 
-(void)popupActionSheet { 
    UIActionSheet *popupQuery = [[UIActionSheet alloc] 
           initWithTitle:nil 
           delegate:self 
           cancelButtonTitle:@"Cancel" 
           destructiveButtonTitle:nil 
           otherButtonTitles:@"Save Image",nil]; 
    popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
    [popupQuery showInView:self.view]; 
    [popupQuery release]; 
} 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: 
(int)buttonIndex { 
    //UIImage* image = [[TTURLCache sharedCache] imageForURL:imageURL]; 
    if (buttonIndex==0){ 
     UIImage* thisImage = [[TTURLCache sharedCache] imageForURL: 
           [_centerPhoto URLForVersion:TTPhotoVersionLarge]]; 
     UIImageWriteToSavedPhotosAlbum(thisImage, nil, nil, nil); 
     //{UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"URL" 
    //message:[_centerPhoto URLForVersion:TTPhotoVersionLarge] delegate:self cancelButtonTitle:@"No" ,otherButtonTitles:@"Yes", nil]; 
     //[alert show];} 
    } 
} 



-(void)createPhotos { 
    images = [[NSArray alloc] initWithObjects: 
       [[[Photo alloc] initWithURL:@"bundle://14.png" smallURL:@"bundle://14.png" 
            size:CGSizeMake(320, 212)] autorelease], 
       [[[Photo alloc] initWithURL:@"bundle://30.png" smallURL:@"bundle://30.png" 
            size:CGSizeMake(320, 212)] autorelease], 
       [[[Photo alloc] initWithURL:@"bundle://back.jpeg" smallURL:@"bundle://back.jpeg" 
            size:CGSizeMake(319, 317)] autorelease], 

       nil]; 

} 



- (void)viewDidLoad { 
    //[self loadView]; 
    [self createPhotos]; // method to set up the photos array 
     self.photoSource = [[PhotoSource alloc] 
         initWithType:PhotoSourceNormal 
         title:@"SexyGirl" 
         photos:images 
         photos2:nil 
         ]; 





} 



@end 
+0

오류가 있습니까? 어느 부분에서 당신이 강타 했나요? – Aravindhan

+0

안녕하세요, 저는 ady를 수정했습니다. – ahyong87

답변

0

, 당신은 사용할 수 있습니다

UIImage *myImage; 
UIImageWriteToSavedPhotosAlbum(myImage,nil,nil,nil); 

를이 방법으로 문제가 아닌 경우, 나는 그것을 얻지 않는다. 문제가있는 곳을 알려주지 않으면 3 페이지 분량의 코드를 게시하는 것은 꽤 쓸모가 없습니다.

+0

안녕하세요, 다음과 같이하고 싶습니다 .http : //sol3.typepad.com/tagalong_developer_journa/2009/12/adding-savetoalbum-to-the-ttphotoviewcontroller.html – ahyong87

+0

덕분에 마침내 문제가 발견되었습니다. ~! – ahyong87

관련 문제