If I were to use the code by @abbood, and change the section "//do stuff with the cell" to incorporate an AlertView that pops up and the user can enter text to change the label of the cell. How would I do that, I tried the code below, but it only pops up the alert and doesn't do anything with what I entered in as the text to the alert. Note: cell has a UILabel named label that I want to change the text of. It appears that the NSLog I entered below to check the value of userEnterThisString is empty, the code has already executed before the text from getTitle is returned. I think I may need to delay the cell.label.text = userEnteredThisString until the AlertView is done, how would I do this? or any other ideas for the code are welcome. the question that generated this code is @ Long press gesture on UICollectionViewCell
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateEnded) {
return;
}
CGPoint p = [gestureRecognizer locationInView:self.collectionView];
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:p];
if (indexPath == nil){
NSLog(@"couldn't find index path");
} else {
// get the cell at indexPath (the one you long pressed)
Cell *cell =
[self.collectionView cellForItemAtIndexPath:indexPath];
// do stuff with the cell
UIAlertView *getTitle = [[UIAlertView alloc] initWithTitle:@"Add Search Keyword" message:nil delegate:self cancelButtonTitle:@"Add" otherButtonTitles:nil];
getTitle.alertViewStyle = UIAlertViewStylePlainTextInput;
NSString * userEnterThisString = [[getTitle textFieldAtIndex:0] text];
// this part doesn't execute (wondering why it doesn't work?)
cell.label.text = userEnterThisString;
NSLog(userEnterThisString);
[getTitle show];
}
}