你不應該有一個問題,設置該單元格的文本字段的代表作爲您的視圖控制器。
這就是你需要做什麼:
1)視圖控制器需要實現UITextFieldDelegate
協議
2)申報文本字段屬性在您的自定義單元格
@property (nonatomic, retain) IBOutlet UITextField *textField;
3)然後將視圖控制器設置爲方法中的文本字段的代理cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
// use this if you created your cell with IB
cell = [[[NSBundle mainBundle] loadNibNamed:@"MyCustomCell" owner:self options:nil] objectAtIndex:0];
// otherwise use this
cell = [[[MyCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
// now set the view controller as the text field delegate
cell.textField.delegate = self;
}
// configure cell...
return cell;
}
我同意。要做到這一點,只需在UITableViewCell實現的初始化中設置委託。例如,在awakeFromNib調用中,只需添加self.YourTextField.delegate = self。 – JeffB6688 2017-04-14 19:00:20
同意這是做到這一點的正確方法。 – GeneCode 2017-04-20 07:46:39