Cell Gesture Problem on XCode12 & iOS14

GorgoasTW
Nov 25, 2020

--

最近將舊專案升級至 Xcode12 時發現了一個 UITableViewCell 在 iOS14 才會有的問題,檢查一下發現跟以前一樣蘋果又動了結構….

如果使用程式碼在cell中加入元件

以前的寫法常常像下面這樣

UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(120.0f, 12.0f, 150.0f, 20.0f)];
[cell addSubview: tf];

但是在 iOS14 如果還是用這樣的寫法的話,使用者點擊輸入框會發現根本不會反應彈出鍵盤,完全沒有反應

現在要改成像是下面這樣的寫法

UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(120.0f, 12.0f, 150.0f, 20.0f)];
[cell.contentView addSubview: tf];

多了一層 contentView 然後就跟以前一樣了…

偉哉蘋果

--

--

GorgoasTW
GorgoasTW

Written by GorgoasTW

iOS Developer/.NET Developer/Father

No responses yet