我有我的代码这个问题,我想添加文本域到我的单元格。它的工作!但是当我以后再试时它没有。我用NSLog调试了一下,得出的结论是cell不是= nil,因此我的代码没有运行。UITableView如果(单元格==空)错误
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Called1");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
cell.accessoryType = UITableViewCellAccessoryNone;
NSLog(@"Called?");
UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
playerTextField.adjustsFontSizeToFitWidth = YES;
playerTextField.textColor = [UIColor blackColor];
if([indexPath row] == 0) {
playerTextField.placeholder = @"yoyo1";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyNext;
} else {
playerTextField.placeholder = @"yoyo2";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyDone;
playerTextField.secureTextEntry = YES;
}
playerTextField.backgroundColor = [UIColor whiteColor];
playerTextField.autocorrectionType = UITextAutocorrectionTypeNo;
playerTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
playerTextField.textAlignment = UITextAlignmentLeft;
playerTextField.tag = 0;
playerTextField.clearButtonMode = UITextFieldViewModeNever;
[playerTextField setEnabled: YES];
[cell.contentView addSubview:playerTextField];
}
return cell;
}
代码NSLog(@"Called?")
没有被调用,但NSLog(@"Called1")
呢。为什么?
谢谢。
工作过,谢谢! –