長押しジェスチャーの後にセルのイメージビューを変更するにはどうすればよいですか?
これを使用すると、セルをクリックすると (長押し)、4 つのカスタマイズされたアイテムが表示されますが、そのうちの 1 つを選択するとアプリがクラッシュします。(:(Cell*)cell および cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"ICUbedRED.png"]]; を削除すると機能します... alertView が表示されることを意味しますが、もちろん画像は表示されません変わりません)。
- (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];
}
}
ボイドは次のとおりです。
- (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"]];
.}
セル構築方法は次のとおりです。
- (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;
}