创建单元格:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
AddEventsCell *cell=
[tableView dequeueReusableCellWithIdentifier:@"addevents"];
NSLog(@"cell %@",cell);
if(cell==nil){
[tableView registerNib:[UINib nibWithNibName:@"addevents"
bundle:nil]
forCellReuseIdentifier:@"addevents"];
cell=[tableView dequeueReusableCellWithIdentifier:@"addevents"];
}
cell.tag=indexPath.row;
return cell;
}
显示单元格:
-(void) tableView:(UITableView *)tableView
willDisplayCell:(AddEventsCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"index path %d == %d",indexPath.row,cell.tag);
if(cell.tag==0){
cell.lableFiledValue.text=@"Event Name";
cell.textFieldValue.placeholder=@"0";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==1){
cell.lableFiledValue.text=@"Category";
cell.textFieldValue.placeholder=@"1";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==2){
cell.lableFiledValue.text=@"Upload Image";
cell.textFieldValue.placeholder=@"2";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==3){
cell.lableFiledValue.text=@"Time";
cell.textFieldValue.placeholder=@"3";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==4){
cell.lableFiledValue.text=@"Location";
cell.textFieldValue.placeholder=@"4";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==5){
cell.lableFiledValue.text=@"Description";
cell.textFieldValue.placeholder=@"5";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==6){
cell.lableFiledValue.text=@"Factilitator";
cell.textFieldValue.placeholder=@"6";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==7){
cell.lableFiledValue.text=@"Price";
cell.textFieldValue.placeholder=@"7";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==8){
cell.lableFiledValue.text=@"Notes";
cell.textFieldValue.placeholder=@"8";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==9){
cell.lableFiledValue.text=@"Duration";
cell.textFieldValue.placeholder=@"9";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==10){
cell.lableFiledValue.text=@"Program";
cell.textFieldValue.placeholder=@"10";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==11){
cell.lableFiledValue.text=@"pre-requiment";
cell.textFieldValue.placeholder=@"11";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==12){
cell.lableFiledValue.text=@"Target";
cell.textFieldValue.placeholder=@"12";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==13){
cell.lableFiledValue.text=@"Contact";
cell.textFieldValue.placeholder=@"13";
[self.textfieldArray addObject:cell.textFieldValue];
}else if(cell.tag==14){
cell.lableFiledValue.text=@"Website";
cell.textFieldValue.placeholder=@"14";
[self.textfieldArray addObject:cell.textFieldValue];
}
}
所有单元格对象都添加到self.textfieldArray
如果我在第一个框中输入值,意味着它将在第 7 个框中显示相同的值。
停止预填充数据。
最佳答案
在AddEventsCell
中实现prepareForReuse
:
-(void)prepareForReuse {
self.lableFiledValue.text = nil;
self.textFieldValue.placeholder = nil;
}
另一件事 - willDisplayCell
每次 tableView 将要显示单元格时调用 - 这意味着当用户来回滚动 tableView 时同一单元格多次。您可能想找到另一种方法来将项目添加到 textfieldArray
。您可以使用 NSMutableArray
和 setObject:atIndexedSubscript:
,或者在添加之前检查给定对象是否已存在于数组中。
关于IOS TableView :Table View Custom Cell While Scrolling It pre-populates the Value in another cell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22170414/