我创建了一个只有 1 个部分的 tableView
,它在所有 indexPath.Row
中一直返回 0。我究竟做错了什么?这是我记录 indexPath
NSLog(@"%@", indexPath);
<NSIndexPath: 0xd2897d0> {length = 2, path = 0 - 0}
<NSIndexPath: 0xd290af0> {length = 2, path = 1 - 0}
<NSIndexPath: 0xd2a5cd0> {length = 2, path = 2 - 0}
<NSIndexPath: 0xd2a8340> {length = 2, path = 3 - 0}
cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
if (indexPath.row < 3) {
TextFieldTableViewCell *accountCell = [tableView dequeueReusableCellWithIdentifier: textFieldCellIdentifier forIndexPath: indexPath];
accountCell.cellTextField.delegate = self;
accountCell.cellLabel.text = [accountArray objectAtIndex: indexPath.row];
if (indexPath.row == 0) {
accountCell.cellTextField.keyboardType = UIKeyboardTypeDefault;
} else if (indexPath.row == 1) {
accountCell.cellTextField.keyboardType = UIKeyboardTypeNumberPad;
} else if (indexPath.row == 2) {
accountCell.cellTextField.keyboardType = UIKeyboardTypeNumberPad;
}
cell = accountCell;
} else if (indexPath.row == 3) {
ACEExpandableTextCell *textViewCell = [tableView expandableTextCellWithId:@"cellId"];
textViewCell.text = [self.cellData objectAtIndex:indexPath.section];
textViewCell.textView.placeholder = @"Placeholder";
cell = textViewCell;
}
return cell;
}
最佳答案
可能是这个问题
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [arry count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
return 1;
}
代替
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
return [arry count];
}
关于ios - indexPath 在所有行中返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25160152/