【发布时间】:2014-10-30 13:05:04
【问题描述】:
感谢您的阅读,
我在UICollectionViewCell 中有两个UITextFields(以及一些标签)。我可以在模拟器中选择两个文本字段,适用于 iPhone 6、6+、5、5s、4s,所有 iOS8。
当我连接我的 iPhone,一个 iPhone 5c iOS7(非 sim)时,我只能选择顶部 UITextField 的左上部分。答案将建议如何选择两个文本字段,并探索其他可能的原因有人无法选择文本字段,以及可能的调试方法。对于那些想知道的人,一旦我让这个应用程序在 ios7 中 100% 运行,我就会升级到 ios8。
我尝试过的解决方案:
- Make sure the textField is inside the known superview
- 创建一个新项目,使其正常工作,并尽可能准确地复制所有内容
- 移动文本字段,使底部的在顶部
- 这让我在同一个小点击区域中选择了新的“顶部”字段。
- 选择 UICollectionView 单元并自动设置第一响应者。这不起作用,因为我希望用户选择哪个字段作为第一响应者。
- 将所有背景元素设置为不同的颜色,以确保没有任何内容与 TextField 重叠
-
Set
UICollectionViewto be Editable -- 它只适用于UITableViews - 确保 collectionview 元素的顺序正确
- 复制并粘贴“Good Text Field”,然后查看是否可以选择。
- Deleting the entire
ViewControllerand starting again. - 确保
UICollectionView单元格具有“启用用户交互”
我的当前设置
- Heres a screenshot of the storyboard
UICollectionView: data-source & delegate = it's superview (UIViewController)-
UICollectionViewCell: 有 4 个出口链接到一个自定义单元 -
UITextFields:代表设置为UIViewController- 通向单元的参考插座
-
EditingDidBegin和EditingDidEnd方法在UIViewController中处理 - 一个文本字段使用选择器输入视图,另一个使用键盘
要明确:
- 我可以让键盘在模拟器中弹出,在我的手机上的小点击区域中弹出
- This is not about retrieving the data from text fields.
- 我可以让测试项目正常工作,但主项目拒绝接受
UITextFields中的点击
相关代码 - UIViewController .m
接口 - Private.m
@interface EnterFinalHRViewController ()
// The current responder showing a keyboard.
@property (nonatomic, assign) id currentResponder;
文本字段方法
- (IBAction)editingDidBegin:(UITextField *)textField {
self.currentResponder = textField;
}
- (IBAction)resignOnTap:(id)sender {
//called from a single tap on the view, gesture recognizer is present
//called when the text field says "Editing did End"
[self.currentResponder resignFirstResponder];
}
//implementation of the cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"swimmerReview";
FinalHeartRateCollectionViewCell *cell = (FinalHeartRateCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; //reuse the cell
Lane *lane = [_lanes objectAtIndex:indexPath.section]; //lanes hold swimmers, so get the lane
Swimmer *swimmer = [lane.swimmers objectAtIndex:indexPath.row]; //swimmers are in the lane, so get the right swimmer
if (swimmer.actualSwimmerName) {
cell.swimmerFullName.text = swimmer.actualSwimmerName;
} else {
cell.swimmerFullName.text = @"Assign Swimmer";
}
cell.finalHeartRate.text = @"--";
//Person Picker is a PickerView that lets the user select a swimmer
cell.swimmerFullName.inputView = PersonPicker;
cell.averageStrokeRate.text = [NSString stringWithFormat:@"Avg SR: %.f", swimmer.strokeRateAvg];
cell.AveragePace.text = [@"Avg Pace: " stringByAppendingString: swimmer.setSplitAvg];
return cell;
}
问题
答案将建议如何选择两个文本字段,并探索其他可能的原因有人无法选择文本字段,以及可能的调试方法。
快速向 SO 的所有贡献者大喊,你们都是这样的资源,我从你们回答的所有问题中阅读并学到了很多东西。这次我实在想不通。
【问题讨论】:
标签: ios objective-c iphone uitextfield uicollectionviewcell