gpt4 book ai didi

ios - 处理 UICollectionView Cell 内 UITextFiled 的键盘返回操作

转载 作者:行者123 更新时间:2023-11-29 05:28:37 25 4
gpt4 key购买 nike

我有一个带有部分的UIcollectionViewCollectionView Cell 由一个 UITextFiled 组成。我创建了一个带有两个箭头按钮的键盘 inputAccessoryView ,如下所示。

现在我的要求是当用户按下箭头按钮时,下一个文本字段应该成为第一响应者。我正在努力如何获取当前选定的文本字段实例和下一个文本字段,因为文本字段是在 CollectionView Cell 内动态生成的。请分享一些如何实现这一目标的想法。

enter image description here

CollectionView Cell 类

@implementation ItemCell

@synthesize txtTitle;

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
txtTitle = [[UITextField alloc] initWithFrame:CGRectMake(5.0, 5.0, 60.0, 30.0)];
[txtTitle setKeyboardType:UIKeyboardTypeDecimalPad];

UIToolbar* keyboardToolbar = [[UIToolbar alloc] init];
[keyboardToolbar sizeToFit];

UIBarButtonItem *prevBarButton = [[UIBarButtonItem alloc]
initWithTitle:@"<" style:UIBarButtonItemStylePlain target:self action:@selector(prevButtonPressed)];

UIBarButtonItem *nextBarButton = [[UIBarButtonItem alloc]
initWithTitle:@">" style:UIBarButtonItemStylePlain target:self action:@selector(nextButtonPressed)];

UIBarButtonItem *flexBarButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];

UIBarButtonItem *doneBarButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self action:@selector(doneButtonPressed)];
keyboardToolbar.items = @[prevBarButton, nextBarButton, flexBarButton, doneBarButton];
self.txtTitle.inputAccessoryView = keyboardToolbar;


[self.contentView addSubview:txtTitle];
}
return self;
}

-(void)prevButtonPressed{
}

-(void)nextButtonPressed{
}

-(void)doneButtonPressed
{
[self.txtTitle resignFirstResponder];
}

View Controller

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

ItemCell *iCell = [cv dequeueReusableCellWithReuseIdentifier:@"ItemCell" forIndexPath:indexPath];
iCell.userInteractionEnabled = TRUE;

iCell.txtTitle.text = [[myArr objectForKey@"section"]objectAtIndex:indexPath.row];

}

最佳答案

我认为您可以使用“标签”来识别选择了哪个文本字段。将“indexPath.row”分配给每个文本字段。这是检测您何时动态创建它的唯一方法

关于ios - 处理 UICollectionView Cell 内 UITextFiled 的键盘返回操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57903392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com