【发布时间】:2014-08-17 10:30:32
【问题描述】:
如果我要使用@abbood 的代码,并更改“//do stuff with the cell”部分以合并弹出的AlertView,用户可以输入文本来更改单元格的标签。我将如何做到这一点,我尝试了下面的代码,但它只会弹出警报,并且不会对我作为警报文本输入的内容做任何事情。注意:单元格有一个名为 label 的 UILabel,我想更改它的文本。我在下面输入的用于检查 userEnterThisString 值的 NSLog 似乎是空的,代码在 getTitle 的文本返回之前已经执行。我想我可能需要延迟 cell.label.text = userEnteredThisString 直到 AlertView 完成,我该怎么做?或任何其他关于代码的想法都是受欢迎的。生成此代码的问题是@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];
}
}
【问题讨论】:
-
使用
UIAlertViewDelegate方法怎么样?检查用户单击按钮时输入的文本? -
我尝试将 UIAlertViewDelegate 方法添加到 .h 文件 @interface CustomViewController : UICollectionViewController
是你的意思吗?或者你需要额外的东西吗?我在这里有点新手,所以非常感谢您的帮助!
标签: ios