2014-10-30 26 views
2

謝謝您的閱讀,內UICollectionViewCell的UITextField不可達

我有兩個UITextFields(有一些標籤一起)一個UICollectionViewCell內。我可以在模擬器中選擇兩個文本字段,對於iPhone 6,6 +,5,5s,4s,全部iOS8,

當我連接我的iPhone,iPhone 5c iOS7(非SIM卡)時,我只能選擇頂部UITextField的左上角部分。一個答案會建議如何選擇兩個文本字段,並探討其他可能的原因,有人不能選擇文本字段,以及可能的解決方法。對於那些想知道的,我會盡快升級到ios8,只要我在ios7中使用這個應用程序100%。

解決方案我已經試過:

  1. Make sure the textField is inside the known superview
  2. 創建一個新項目,獲取工作正常,並複製一切儘可能準確
  3. 轉移文本字段,以便下一個在頂部
  4. 這有讓我在同一個小命中區域選擇新的「頂部」領域的結果。
  5. 選擇UICollectionView單元並自動設置第一響應者。這不起作用,因爲我希望用戶選擇使哪個字段成爲第一響應者。
  6. 設置所有的背景元素,以不同的顏色,以確保沒有被重疊的文本字段
  7. Set UICollectionView to be Editable - 它只有UITableViews
  8. 工作確保的CollectionView元素是按照正確的順序
  9. 複製和粘貼「良好的文本字段「,看看是否可以選擇。
  10. Deleting the entire ViewController and starting again.
  11. 確保UICollectionView細胞具有 「用戶交互啓用

我目前開設

  • Heres a screenshot of the storyboard
  • UICollectionView: data-source & delegate = it's superview (UIViewController)
  • UICollectionViewCell:有4個網點鏈接到定製細胞
  • UITextFields:代表被設置爲UIViewController
    • 引用出口通向細胞在UIViewController
    • 一個文本框處理
    • EditingDidBeginEditingDidEnd方法使用一個選擇器輸入另一個鍵盤

要明確:

  1. 我可以讓鍵盤在模擬器上彈出,而我的手機上的小災區
  2. This is not about retrieving the data from text fields.
  3. 我能得到的測試項目工作,但主體工程不服水龍頭在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的貢獻者,你都是這樣的資源,並且我已經閱讀並從所有你已經回答的問題中學到了很多東西。這次我無法弄清楚。

回答

0

聽起來像你的cell框架(或它的一個superviews)不夠大。快速和骯髒的方式來調試,這將是添加此和水龍頭,你知道你可以訪問該文本框的左上角:

- (IBAction)editingDidBegin:(UITextField *)textField { 
    self.currentResponder = textField; 
    UIView *superview = textField; 
    while (superview != nil) { 
    [superview setClipsToBounds:YES]; 
    superview = [superview superview]; 
    } 
} 

應該在哪些方面你有框架的問題。從那裏,您可以準確檢測哪個視圖有錯誤的界限,並調查您爲其設置的自動佈局/常規佈局屬性。

+0

你說得對。有一個子視圖添加到自定義UICollectionViewCell(不是我),所有我的界面元素都在裏面。在我的測試項目中,未知的子視圖重新調整爲自定義單元格的寬度,但是在我的主項目中它保持在50 x 50,裁剪並記錄名稱顯示給我。現在瞭解它爲什麼被添加,以及如何讓它擴展以填充父視圖。 – 2014-10-30 21:09:37

1

@Ian MacDonald你提供了一個調試方法,導致這個發現Content View Not Resizing的寶石。

我的問題是運行ios7與ios8之一。我的自定義單元格中的佈局子視圖方法的一個簡單覆蓋修復了問題。大喊@Daniel Plamann,你可以在上面的頁面上找到他的解決方案。

//把你UICollectionViewCell自定義類

- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 

    BOOL contentViewIsAutoresized = CGSizeEqualToSize(self.frame.size, self.contentView.frame.size); 

    if(!contentViewIsAutoresized) { 
    CGRect contentViewFrame = self.contentView.frame; 
    contentViewFrame.size = self.frame.size; 
    self.contentView.frame = contentViewFrame; 
    } 
} 

我的測試項目工作的原因是因爲我前兩天做它,我的主要項目是由10個月前在iOS8上發射前裏面。所以,如果你發現你做的一切正確,按照上述10個步驟,你仍然無法選擇你的子視圖,這裏還有一個。

相關問題