2013-03-01 2 views
0

iPhone 프로그래밍에 익숙하지 않습니다. 아래 코드를 사용하여 이미지를 미리보기 이미지에 표시하고 있습니다. 거기에서 우리는 여러 이미지를 선택할 수 있으며 또한 이미지를 선택하거나 선택 해제 할 수 있습니다. 일부 이미지를 선택하면 다음 이미지에서 선택한 이미지가 표시됩니다. 그 때문에 나는 다른 방법을 사용했습니다. 그러나 문제는 이미지를 축소판 그림으로 표시하는 것입니다. 그러나 이미지를 선택하면 예외가 있음을 의미합니다. 어떤 몸이라도 이것을 해결할 수있는 방법을 말해 줄 수 있습니까?iPhone에서 여러 이미지를 선택하지 않았습니다.

- (void)viewDidLoad 
{ 
    [email protected]"All Images"; 
     mImageSelected=[[NSMutableArray alloc]init]; 
    self.view.backgroundColor=[UIColor whiteColor]; 
    mFirst=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"one.jpg"]]; 
    mFirst.frame=CGRectMake(10, 10, 60, 50); 

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] 
             initWithTarget:self 
             action:@selector(actionHandleTapOnImageView:)]; 
    mFirst.userInteractionEnabled = YES; 
    [mFirst addGestureRecognizer:singleTap]; 
    [self.view addSubview:mFirst]; 
    msSec=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"two.jpg"]]; 
    msSec.frame=CGRectMake(80, 10, 60, 50); 
    UITapGestureRecognizer *secsingleTap = [[UITapGestureRecognizer alloc] 
             initWithTarget:self 
              action:@selector(actionHandleTapOnImageView:)]; 
    msSec.userInteractionEnabled = YES; 
    [msSec addGestureRecognizer:secsingleTap]; 

    [self.view addSubview:msSec]; 
    mThird=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"three.jpg"]]; 
    mThird.frame=CGRectMake(150, 10, 60, 50); 
    UITapGestureRecognizer *trdsingleTap = [[UITapGestureRecognizer alloc] 
              initWithTarget:self 
              action:@selector(actionHandleTapOnImageView:)]; 
    mThird.userInteractionEnabled = YES; 
    [mThird addGestureRecognizer:trdsingleTap]; 

    [self.view addSubview:mThird]; 
    m4th=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"four.jpg"]]; 
    m4th.frame=CGRectMake(220, 10, 60, 50); 
    UITapGestureRecognizer *frthsingleTap = [[UITapGestureRecognizer alloc] 
              initWithTarget:self 
              action:@selector(actionHandleTapOnImageView:)]; 

    m4th.userInteractionEnabled = YES; 
    [m4th addGestureRecognizer:frthsingleTap]; 
    [self.view addSubview:m4th]; 
    m5th=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"five.jpg"]]; 
    m5th.frame=CGRectMake(10, 70, 60, 50); 
    UITapGestureRecognizer *fifthsingleTap = [[UITapGestureRecognizer alloc] 
              initWithTarget:self 
               action:@selector(actionHandleTapOnImageView:)]; 

    m5th.userInteractionEnabled = YES; 
    [m5th addGestureRecognizer:fifthsingleTap]; 
    [self.view addSubview:m5th]; 
    UIButton *theSshowButton=[[UIButton alloc]init]; 
    theSshowButton.frame=CGRectMake(100, 300, 100, 30); 
    theSshowButton.layer.borderWidth=2; 
    theSshowButton.layer.borderColor=[UIColor purpleColor].CGColor; 
    theSshowButton.layer.cornerRadius=5; 
    theSshowButton.backgroundColor=[UIColor greenColor]; 
    [theSshowButton setTitle:@"Show" forState:UIControlStateNormal]; 
    [theSshowButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
    [theSshowButton addTarget:self action:@selector(show) forControlEvents:UIControlEventTouchUpInside]; 
    [self.view addSubview:theSshowButton]; 

    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 
-(void)actionHandleTapOnImageView:(UITapGestureRecognizer *) in_ImageSenderTap 
{ 
if (in_ImageSenderTap.view.tag ==0) 
    { 


    mTick=[[UIImageView alloc]initWithImage:[UIImage imageNamed: @"mark.jpg"]]; 
    mTick.frame=CGRectMake(0, 0, in_ImageSenderTap.view.frame.size.width*0.3, in_ImageSenderTap.view.frame.size.height*0.4); 

     [mImageSelected addObject:[in_ImageSenderTap.view accessibilityIdentifier]]; 

     [in_ImageSenderTap.view addSubview:mTick]; 


     in_ImageSenderTap.view.tag=1; 
    } 
     else 
    { 
    for (UIView *subviews in in_ImageSenderTap.view.subviews) 
     { 


      UIImageView *theSubview=(UIImageView*)subviews; 

      [theSubview removeFromSuperview]; 
      [mImageSelected removeObjectIdenticalTo:[in_ImageSenderTap.view accessibilityIdentifier]]; 

     } 
     in_ImageSenderTap.view.tag=0; 
    } 


} 

이와 유사하게 일부 표현을 보여줍니다.

2013-03-01 12:01:21.332 ImageStuf[588:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' 
*** First throw call stack: 
(0x159a012 0x12a7e7e 0x154db6a 0x154da20 0x37e0 0x4b685a 0x4b599b 0x4b70df 0x4b9d2d 0x4b9cac 0x4b1a28 0x21e972 0x21ee53 0x1fcd4a 0x1ee698 0x25fcdf9 0x25fcad0 0x150fbf5 0x150f962 0x1540bb6 0x153ff44 0x153fe1b 0x25fb7e3 0x25fb668 0x1ebffc 0x1cd2 0x1c05 0x1) 
libc++abi.dylib: terminate called throwing an exception 
(lldb) 

내가 -(void)actionHandleTapOnImageView:(UITapGestureRecognizer *) in_ImageSenderTap이 작업을 잘하지만 array.Can에서의 저장하지 않는 이미지를 의미한다이 방법의 코드 아래에 의견을 경우 어떤 몸 찾는 방법이 감사 를 풀기가하는 아슬 람

[mImageSelected addObject:[in_ImageSenderTap.view accessibilityIdentifier]]; 
+0

NSLog & Check [in_ImageSenderTap.view accessibilityIdentifier]. 이것은 없어서는 안됩니다. –

답변

0

을 말해 복수 선택 PSTCollectionView을 사용할 수 있습니다. 위대한 라이브러리 및이 또한 iOS 5 gridView 및 UICollectionView 같이 작동하는 iOS6 위의 작동합니다.

모두 최고 !!!

0

우선 배열에 accessibilityIdentifier을 삽입하는 것이 왜 썸네일 자체를 추가 할 수 있습니까? 이렇게하면 nil을 추가하지 않아도됩니다. 이는 크래시를 생성하는 것입니다. 미리보기 이미지에 accessibilityIdentifier을 설정하지 않았습니다.

두 번째 이유는 UITapGestureRecognizer의 인스턴스 5 개를 만드는 이유는 무엇입니까? addGestureRecognizer: 인 경우 동일한 인스턴스를 사용하기 만하면 5 가지 버전이 필요하지 않습니다.

0

NSArray에 nil을 삽입하려고 시도 했으므로 예외가 발생했습니다. 삽입 할 요소를 확인해야합니다.

나는 여러 이미지를 선택하는 ALAssetLibrary를 사용할 수 있다고 생각 :

[_assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 
    if (group) { 
     [self.groupArray addObject:group]; 
    } 
} failureBlock:^(NSError *error) { 
    NSLog(@"Group not found!\n"); 
}]; 

- (void)getImages 
{ 
    if (!self.assetsArray) { 
     _assetsArray = [[NSMutableArray alloc] init]; 
    } 

    if (!self.assetsLibrary) { 
     _assetsLibrary = [[ALAssetsLibrary alloc] init]; 
    } 

    @autoreleasepool { 
     [self.assetsGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 
      if (result) { 
       TTAsset *ttAsset = [[TTAsset alloc] initWithAsset:result]; 
       [self.assetsArray addObject:ttAsset]; 
       [ttAsset release], ttAsset = nil; 
      } 
     }]; 
    } 

    [self.tableView reloadData]; 
} 

그 후, 당신은 ALAsset의 축소판 속성을 사용할 수 있습니다.

ELCImagePickerController은 좋은 출발점입니다.

관련 문제