길게 누르는 동작 후에 셀 이미지 뷰를 변경하려면 어떻게해야합니까?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;
}