所以,这让我发疯了......一切都很好,除非我的数据源:一个NSMutableArrray : _names包含的项目多于UITableView中可见的行数:namesTable。然后所有的地狱都崩溃了……细胞相互重叠,有空的细胞,重复的细胞。
这是我的设置代码。
@interface DetailViewController ()
{
NSMutableArray *_names;
}
我的 viewDidLoad 方法:
- (void) viewDidLoad
{
[super viewDidLoad];
self.navigationController.toolbar.barStyle = UIBarStyleBlackOpaque;
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(handleBack:)];
self.navigationItem.leftBarButtonItem = backButton;
if (!_names)
_names = [[NSMutableArray alloc] init];
}
和 cellForRowAtIndexPath:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"MyCustomCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
UITextField *nameTextField;
if (!cell || refreshCells)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
self.view.bounds.origin.y+10,
self.view.bounds.size.width-19,
26.0)];*/
nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(self.view.bounds.origin.x+10,
self.view.bounds.origin.y+4,
self.view.bounds.size.width-19,
34.0)];
}
nameTextField.adjustsFontSizeToFitWidth = YES;
nameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
nameTextField.backgroundColor = [UIColor clearColor];
nameTextField.autocorrectionType = UITextAutocorrectionTypeNo;
nameTextField.autocapitalizationType = UITextAutocapitalizationTypeWords;
nameTextField.textAlignment = UITextAlignmentLeft;
nameTextField.font = [UIFont fontWithName:@"Noteworthy-Bold" size:22.0];
nameTextField.keyboardType = UIKeyboardTypeDefault;
nameTextField.returnKeyType = UIReturnKeyDone;
nameTextField.clearButtonMode = UITextFieldViewModeNever;
nameTextField.delegate = self;
nameTextField.userInteractionEnabled = NO;
NSString *object = _names[indexPath.row];
nameTextField.text = [object description];
[cell.contentView addSubview:nameTextField];
cell.selectionStyle = UITableViewCellEditingStyleNone;
return cell;
}
谁能告诉我我做错了什么?