2012-06-28 4 views
0

iCarousel을 그림과 같이 here 캐 러셀 유형의 라이너 캐 러셀과 함께 사용하고 삭제 기능을 구현했습니다. 회전식으로 이미지를 삭제할 수 있으며 다른 이미지를 삭제하려고 시도합니다. 가시 화면에서 iomage 회전식 프레임으로 이동하여 삭제합니다.
원래 위치에서 이미지를 삭제해야합니다.iCarousel iphone에서 다른 위치의 이미지 삭제 기능을 구현하는 방법

- (void)loadView { 

    [super loadView]; 

    self.view.backgroundColor = [UIColor blackColor]; 

    carousel = [[iCarousel alloc] initWithFrame:CGRectMake(-130,300, 320, 100)]; 
    carousel.dataSource = self; 
    carousel.delegate=self; 
    carousel.type = iCarouselTypeLinear; 
    carousel.scrollEnabled=YES; 

    imageView=[[UIImageView alloc]initWithFrame:CGRectMake(60, 50, 200, 200)]; 
    [self.view addSubview:imageView]; 


} 

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view 
    { 

    UIImage *image = [imagesArray objectAtIndex:index]; 

    UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom]; 
    button.frame = CGRectMake(0,0, 60, 60); 
    [button setBackgroundImage:image forState:UIControlStateNormal]; 
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
    button.titleLabel.font = [button.titleLabel.font fontWithSize:50]; 
    [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; 
    button.tag=index; 
    NSLog(@"tag is %d",button.tag); 

    UIButton *deleteButton=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    deleteButton.frame= CGRectMake(50, -5, 20 ,20); 
    UIImage *img = [UIImage imageNamed:@"close.png"]; 
    [deleteButton setImage:img forState:UIControlStateNormal]; 
    [deleteButton addTarget:self action:@selector(deleteButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
    [button addSubview:deleteButton]; 

    return button; 
} 

-(void)deleteButtonClicked:(int)sender 
{ 
    NSInteger currentIndex = carousel.currentItemIndex; 
    [carousel removeItemAtIndex:currentIndex animated:YES]; 

} 

제발 도와주세요.

NSInteger index = carousel.currentItemIndex; 
    [carousel removeItemAtIndex:index animated:YES]; 
    [imagesArray removeObjectAtIndex:index]; 

가이 추가 :

enter image description here

+0

배열에서 삭제 하시겠습니까? 원래 위치에서 이미지를 삭제하면 무엇을 의미합니까? – Bazinga

+0

- (BOOL) 회전식 고정대 : (iCarousel *) 회전식 개폐구 { return NO; } 이미 내 코드에서 이것을 사용하고 있습니다. – Valli

+0

그것이 현재 위치에있을 때 IT 부서에서 삭제해야합니다. 그러나 코드를 사용하여 caroselframe 위치로 스크롤됩니다. – Valli

답변

2

당신은 carousel.currentItemIndex에서 항목을 삭제 안, 그것은 단지 현재 중심이다 항목을 클릭합니다.

당신이 클릭 버튼에 대한 올바른 항목 인덱스를 얻으려면 다음을 수행하십시오

-(void)deleteButtonClicked:(id)sender 
{ 
    //get the index of the item view containing the button that was clicked 
    NSInteger index = [carousel indexOfItemViewOrSubview:sender]; 

    //update the data model (always do this first) 
    [imagesArray removeObjectAtIndex:index]; 

    //remove item from carousel 
    [carousel removeItemAtIndex:index animated:YES]; 
} 
+0

경고 : 경고 : 인스턴스 메소드 '-indexOfitemViewOrSubview :'를 찾을 수 없습니다. (반환 유형 기본값 (Native)) 'NSInteger'(일명 'int')를 초기화하는 호환되지 않는 포인터입니다. 'id') [3] 그리고 내 응용 프로그램이 추락되었습니다 .. – Valli

+0

발신자 매개 변수는 원래 코드와 동일하게 유형이 아닌 유형 ID 여야합니다. indexOfitemViewOrSubview는 "Of"뒤에 대문자 "i"가 있어야합니다. 이는 내 파트의 오타였습니다. –

1

이 시도

- (void)awakeFromNib 
{  
    if (self) { 
     //set up carousel data 
     wrap = NO; 
    } 
} 

또는 확인하여

carousel.type = iCarouselTypeCustom;

carousel.type = iCarouselTypeLinear;

다음이 구현 : 그건 당신이 클릭 버튼에 해당하는 항목이 없기 때문에 [carousel reloadData];

+0

제 편집을 확인하십시오 .I image1을 삭제하려고 시도합니다. 삭제 중입니다. 4 번째 이미지 (삭제할 이미지가 필요합니다)를 삭제하려고 시도합니다. 스크린 샷에서 첫 번째 이미지 위치로 스크롤됩니다. – Valli

+0

삭제 하시겠습니까? 'iCarousel'에서 아이템을 지울 때 자동으로 위치를 변경합니다. – Bazinga

+0

wrap = NO; 여기에 오류가 발생했습니다. 선언되지 않은 식별자 랩을 사용합니다. – Valli

관련 문제