0

길게 누르는 동작 후에 셀 이미지 뷰를 변경하려면 어떻게해야합니까?longpress 사용자 정의 항목 UICollectionViewCell 이미지 변경

내가 셀 (longpress)을 클릭하면 사용자 정의 된 4 가지 항목이 표시되지만 하나를 선택하면 앱이 다운됩니다. (제거하는 경우 : (셀 *) 셀 및 cell.imageView.image = [UIImage imageNamed : [NSString stringWithFormat : @ "ICUbedRED.png"]]; 그것은 작동합니다 ... alertView 나타납니다하지만 물론 이미지를 의미하지 않습니다. 변화 없음).

- (void)hiDep:(Cell*)cell 
{ 
    NSLog(@"Bed is HiDep"); 

    cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"ICUbedRED.png"]]; 




    UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:@"This Bed is High  Dependency" 
               message:@"" 
               delegate:self cancelButtonTitle:@"OK"  otherButtonTitles:nil, nil]; 



    [testAlert show]; 
    [testAlert release]; 


    } 

- (void)lowDep:(Cell*)cell 
{. 
    cell.imageView.image = [UIImage imageNamed:[NSString  stringWithFormat:@"ICUbedYELLOW.png"]]; 
..} 

- (void)free:(Cell*)cell 
{.. 
    cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"ICUbedGREEN.png"]]; 
.} 

- (void)booked:(Cell*)cell 
{.. 
    cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"ICUbedBLUE.png"]]; 
.} 

셀 조립 방법은 다음과 같다 :

- (void)longPress:(UILongPressGestureRecognizer *)recognizer { 
    if (recognizer.state == UIGestureRecognizerStateBegan) { 
     Cell *cell = (Cell *)recognizer.view; 
     [cell becomeFirstResponder]; 

     UIMenuItem *highDep = [[UIMenuItem alloc] initWithTitle:@"High Dependency" action:@selector(hiDep:)]; 
     UIMenuItem *lowDep = [[UIMenuItem alloc] initWithTitle:@"Low Dependency" action:@selector(lowDep:)]; 
     UIMenuItem *booked = [[UIMenuItem alloc] initWithTitle:@"Booked"  action:@selector(booked:)]; 
     UIMenuItem *free = [[UIMenuItem alloc] initWithTitle:@"Free" action:@selector(free:)]; 

      UIMenuController *menu = [UIMenuController sharedMenuController]; 
    [menu setMenuItems:[NSArray arrayWithObjects:booked, highDep, lowDep, free, nil]]; 
     [menu setTargetRect:cell.frame inView:cell.superview]; 
     [menu setMenuVisible:YES animated:YES]; 



    } 
} 

보이드는

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView  cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 

    static NSString *identifier = @"Cell"; 
    Cell *cvc = (Cell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 

    int i = indexPath.row%[labelArray count]; 
    number = i; 

    UILongPressGestureRecognizer *recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; 



    [cvc addGestureRecognizer:recognizer]; 


    cvc.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"icubed.png"]]; 
    cvc.label.text = [labelArray objectAtIndex:number]; 

     return cvc; 


} 

답변

0

은 개체 retured 그것 때문에

cell.imageView.image = [UIImage imageNamed:[NSString stringWi...... 

대해 충돌한다 @dottorfeelgood 메소드 l의 param로서 이케

  • (무효) lowDep : (셀 *) 세포 이 클래스 셀이 아닌의 retured PARAM 클래스 UIMenuItem이다. 셀이 아닌 메뉴 항목을 클릭하기 때문입니다.

현재 수행중인 작업 대신 UICollectionView에서 기본적으로 제공하는 UICollectionCell 솔루션에서 MenuItems 및 해당 작업을 사용할 수 있습니다. 이 튜토리얼 here을 확인할 수 있습니다!

은 그냥 3 대리자 메서드를 구현하고

// These methods provide support for copy/paste actions on cells. 
// All three should be implemented if any are. 
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath; 
- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender; 
- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender; 

하고있는 viewDidLoad에서 sharedMenuController에 필요한 사용자 정의 메뉴 아이템을 설정합니다.

호프가 도움이 되었기를 바랍니다. 제 나쁜 문장을 형성하는 데 도움이됩니다.

관련 문제