Also im Grunde müssen Sie die bestimmte Zelle aktualisieren und seine Höhe erhöhen. Dafür müssen Sie die Methoden UITextFieldDelegate
implementieren, um sicherzustellen, dass Sie benachrichtigt werden, wenn Textfeld im Bearbeitungsmodus ist.
Sie müssen auch einen IndexPath der aktuellen Zelle pflegen, um die Höhe für die bestimmte Zelle zu erhöhen.
@property(nonatomic, strong) NSIndexPath *selectedIndexPath;
Stellen seinen Anfangswert zu nil
Implementieren Delegatmethode
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
UITableViewCell *cell = (UITableViewCell*)textField.superview;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
if(indexPath != nil) //Returns nil if cell is not visible
{
if(self.selectedIndexPath != nil)
{
//We need to reload two cells - one to hide UIButton of current cell, make visible the new UIButton for which textfield is being currently edited
NSIndexPath *previousIndexPath = self.selectedIndexPath;
self.selectedIndexPath = indexPath;
[self.tableView reloadRowsAtIndexPaths:@[indexPath, previousIndexPath] withRowAnimation:UITableViewRowAnimationNone];
}
else
{
//Reload the cell to show the button
self.selectedIndexPath = indexPath;
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
}
}
Sobald die Zelle neu geladen wird, stellen Sie sicher, dass Sie die Höhe mit Hilfe aktualisieren Auch UITableViewDelegate Methode
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.selectedIndexPath && [indexPath compare:self.selectedIndexPath] == NSOrderedSame)
{
return kHeightWithButton; //assuming its some constant defined in the code
}
return kHeightWithoutButton;
}
abhängig davon, wie Sie mit Einschränkungen für Ihre 01 umgehenMöglicherweise müssen Sie die updateConstraints-Methode der Zelle aufrufen. Ein Beispielcode wie be
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTableViewCell *cell; //Assuming the you have some custom class to handle cell
cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
if(cell == nil)
{
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"myCell"];
//... code for initialization
cell.textField.delegate = self; //set the delegate to self so that we get delegate methods
}
if(self.selectedIndexPath && [indexPath compare:self.selectedIndexPath] == NSOrderedSame)
{
cell.button.hidden = NO;
}
else
{
cell.button.hidden = YES;
}
[cell updateConstraints];//update constraint to adjust the UIButton's visibility and constraints
//... other code if any
return cell;
}
Hoffe es hilft!
Ques nicht klar. –
fügen Sie auch Ihre Codes hinzu. – jo3birdtalk
Haben Sie versucht, die Zelle neu zu laden? –