Add UITableViewCell with UITextField Dynamically - iphone

I'm attempting to have a UITableView that I can dynamically add and remove rows from, and the rows have a UITextField in them. For adding the rows, I'm using the code:
- (void) addRow
{
[nameArray addObject:[NSString stringWithFormat:#"%i", x]];
[self.tableView reloadData];
x++;
}
And I'm just doing a count of nameArray to get how many rows I have in my tableView. Then, inside of cellForRowAtIndexPath, I've got the following code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
/*Default Apple-y stuff*/
...
if ([indexPath row] == 0) {
playerTextFieldZero = [[UITextField alloc] initWithFrame:CGRectMake(20, 10, 185, 30)];
playerTextFieldZero.adjustsFontSizeToFitWidth = YES;
playerTextFieldZero.placeholder = #"Name";
playerTextFieldZero.textColor = [UIColor blackColor];
playerTextFieldZero.returnKeyType = UIReturnKeyDone;
playerTextFieldZero.backgroundColor = [UIColor whiteColor];
playerTextFieldZero.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
playerTextFieldZero.textAlignment = UITextAlignmentLeft;
playerTextFieldZero.tag = 0;
playerTextFieldZero.delegate = self;
playerTextFieldZero.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
[playerTextFieldZero setEnabled: YES];
[cell addSubview:playerTextFieldZero];
[playerTextFieldZero becomeFirstResponder];
[playerTextFieldZero release];
}
...
/*More of those in here*/
...
return cell;
}
I've got multiple issues with this code. The first issue is I'm doing a preset number of UITextFields, so that I can call them all in textFieldShouldReturn. Is there a good way for me to generate UITextFields that will return when I press the done key?
The second biggest issue with the way I'm doing this right now is my UITextFields get cleared every time I add a new one. Any idea why?

To solve your first issue I would begin by pulling the UITextField creation code into a method..
- (UITextField*)textFieldForCell:(UITableViewCell*)cell withDelegate:(id<UITextFieldDelegate>*)delegate {
UITextField textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10, 185, 30)];
textField.delegate = self;
....
[cell addSubview:playerTextFieldZero];
[textField release];
}
Then invoke the new method in your tableView:cellForRowAtIndexPath: method...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
// Custom initialization code
[self textFieldForCell:cell withDelegate:self];
}
Now to make sure that your UITextField's respond to the return key implement the textFieldShouldReturn: method of your UITextFieldDelegate (probably your UITableViewController) to always return true...
-(bool)textFieldShouldReturn:(UITextField*)textField {
return YES;
}
As for your second issue, I believe this is a result of directly invoking reloadData. This will force your UITableView to recreate its cells. This in turn recreates your UITextFields and you subsequently lose their state/text. I think your next logical step will be to introduce a model (NSMutableArray) that stores the state of each UITextField. You could begin by saving the text of the field into the array upon the UITextFieldDelegate receiving the textFieldShouldReturn message.

Related

how to add a textfield on last row in tableview in iPhone?

when i press the new button i need to add a textfield on last row of tableview.
can any one explain the flow.
Thanks in advance.
Just i tried this scenario.
Create a one Boolean variable like this
BOOL newButtonPress = NO;
then fallow the below code
-(IBAction)newButtonClicked:(id)sender{
if (self.newButtonPress == NO) {
//if new button press then newbuttpress is yes and reload the tableview
self.newButtonPress = YES;
[self .reloadTableview reloadData];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(self.newButtonPress == YES)//creating noOfRows when newbutton pressed
{
return [self.itemNames count]+1;
}
else {
return [self.itemNames count];
}
}
Then add the below code into the cellForRowAtIndexPath method
//when new button is pressed adding new cell
if (self.newButtonPress == YES) {
if([self.itemNames count] == [indexPath row]){
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//creating the textfield if new button is pressed
UITextField *extraField = [[UITextField alloc] initWithFrame:CGRectMake(80, 6, 100, 30)];
extraField.borderStyle = UITextBorderStyleNone;
extraField.textAlignment = UITextAlignmentCenter;
[extraField becomeFirstResponder];
[extraField setDelegate:self];
[cell addSubview:extraField];
[extraField release];
}
}
If you just want the text field to appear at the end of the table, why not consider using UITableview's tableFooterView property?
In that case you don't have to ensure that you return the UITextField in your delegate methods.
You should nearly be able to drag drop a new UITextField in your Tableview if you are using InterfaceBuilder or XCode 4.
I am very new to iphone coding,i want to share my thoughts. If that is wrong please ignore.
In cellForRowAtIndexPath method u need to set a textfield in
if(indexPath.row==numberOfRows-1) condition.
In button pressed method u can set textField.hidden=NO and in viewdidload textField.hidden=YES.

TableView is not loading data?

In my Map application I have segment controller on main screen and using that I have Map View & tableview(both are UIView). I have tried everything but my data is not loading in my tableview. Here is my tableview code. Here marker is attribute in my xml file which contain Showroom name and Iam able to parse this.
.h file
#interface HViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> {
UITableView *_tableView;
}
#property (nonatomic, retain) IBOutlet UITableView *_tableView;
#end
.m file
Edited = with ViewWillAppear,viewDieLoad, segement action method
#synthesize tableView;
- (void)viewDidLoad {
appDelegate = (HAppDelegate *)[[UIApplication sharedApplication] delegate];
[segmentedControl addTarget:self action:#selector(segmentAction:)
forControlEvents:UIControlEventValueChanged];
}
- (void)viewWillAppear:(BOOL)animated
{
self._tableView.rowHeight = 80.0;
[_tableView reloadData];
}
-(void)segmentAction:(id)sender;{
UISegmentedControl* segCtl = sender ;
if( [segCtl selectedSegmentIndex] == 0 )
{
NSLog(#"segmentAction mapView");
mapView.hidden = NO;
_tableView.hidden = YES;
//[ self.view addSubview:mapView] ; // adding view to segmentindex 0
}
if( [segCtl selectedSegmentIndex] == 1 )
{
NSLog(#"segmentAction _tableview");
_tableView.hidden = NO;
mapView.hidden = YES;
//[ self.view addSubview:_tableview] ;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(#"appDelegate.markers _tableview");
return [appDelegate.markers count];
}
//method to print row(showroom count on Header)
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section {
if(section == 0)
return [NSString stringWithFormat:NSLocalizedString(#"ShowRooms[%d]", #"Showroom format"), [appDelegate.markers count]];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSUInteger const kShowroomNameLabelTag = 2;
UILabel *ShowroomNameLabel = nil;
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
ShowroomNameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(50, 1, 300, 20)] autorelease];
ShowroomNameLabel.tag = kShowroomNameLabelTag;
ShowroomNameLabel.font = [UIFont boldSystemFontOfSize:18];
[cell.contentView addSubview:ShowroomNameLabel];
NSLog(#"UITableViewCell.markers _tableview");
}
else
{
ShowroomNameLabel = (UILabel *)[cell.contentView viewWithTag:kShowroomNameLabelTag];
}
marker *aMarker = [appDelegate.markers objectAtIndex:indexPath.row];
//ShowroomNameLabel.text = aMarker.name;
ShowroomNameLabel.text= [NSString stringWithFormat:#"ShowroomName= %#", aMarker.name];
return cell;
}
In my tableview Header it shows data count correctly but not showing data.
I have connected delegate,datasource,_tableview to fileOwner of the HViewController in which I have put above code. Plz suggest something where I am wrong. I am parsing XML file and getting data in console alos I can show it on Map. But I am not able to load data in my tableview.
Try moving [_tableView reloadData] to viewWillAppear.
UITableViewController reloads the table view's data in viewWillAppear, not viewDidLoad. I can't tell you the exact reason for which this would make a difference, though I can think of several. Anyway, it's worth a try.
EDIT:
RESPONSE TO COMMENTS
If titleForHeaderInSection: is being called, then there is a data source connected to a table view. So, the problem is not a lack of a data source connection.
I am guessing you have 2 table views in your .xib file: a large one & a short one below it. The large table view is not connected to the data source, so it just displays blank lines. The short table view is connected to the data source. But, it is just tall enough for a header and has no space left to display any cells. Thus, titleForHeaderInSection: is called, but cellForRowAtIndexPath: is not because there is no space to display any cells.
Note that this is just a guess, but it is the only scenario I can think of that would cause the behavior you described. The code you posted looks ok, although a bit more complicated than necessary.
There is no question that reloadData should be in viewWillAppear. That's where the Apple engineers put it when they created the UITableViewController class. So, to put it elsewhere, you have to believe you know better than they do.

UITextField - crash on delegates that return BOOL

I have a UITextField that I am adding to a UITableViewCell to use as a search field for a long list of accounts. I have added it as follows:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
if ((indexPath.section < accountsection) && (hasSearch) && (indexPath.row == 0))
{
// Search
if (!searchField)
{
searchField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10, cell.frame.size.width - 40, 25)];
[searchField setEnabled:YES];
searchField.placeholder = NSLocalizedString(#"Search", #"search");
searchField.keyboardType = UIKeyboardTypeDefault;
searchField.returnKeyType = UIReturnKeySearch;
searchField.autocorrectionType = UITextAutocorrectionTypeNo;
searchField.clearButtonMode = UITextFieldViewModeAlways;
searchField.delegate = self;
[cell addSubview:searchField];
[searchField release];
}
// Clean up an account label if needed
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.text = #"";
cell.detailTextLabel.text = #"";
// Show the search field if it was hidden by a text label
searchField.hidden = NO;
[cell bringSubviewToFront:searchField];
}
}
To detect edits to the text field, I have set up the UITextFieldDelegate in the header and trap the following delegate calls:
#interface AccountViewController : UITableViewController <UITextFieldDelegate> {
BOOL hasSearch;
UITextField *searchField;
...
}
In the implementation, I then handle these delegate methods:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(#"Done editing");
[self filterAccountsBy:textField.text];
[textField resignFirstResponder];
return NO;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSLog(#"Searching for %#", string);
[self filterAccountsBy:string];
return YES;
}
However in the second one, unless I return YES, the text never changes; in the first one, returning YES seems to not affect me. But when I return YES in either, I get a nasty EXC_BAD_ACCESS.
I must be missing something in my manual adding of this UITextField to my cell but I can't figure out what it is... can anyone assist?
Many thanks.
EDIT: As suggested below, I commented out the filterAccounts call and my app now no longer crashes. Here is the full code for this method:
- (void)filterAccountsBy:(NSString *)filterstring
{
[accounts removeAllObjects];
if (([filterstring length] == 0) && (!isChooser) && (![vpmsConn isDomainLogon])) {
[accounts addObject:[[vpmsConn accounts] objectAtIndex:0]];
}
if ([filterstring length] == 0) {
[accounts addObjectsFromArray:[cache accounts]];
} else {
for (AccountItem *ac in [cache accounts])
{
BOOL found = NO;
// Name search
if ([[ac.clientName uppercaseString] rangeOfString:[filterstring uppercaseString]].location != NSNotFound) {
found = YES;
}
//more similar searches
if (found) {
[accounts addObject:ac];
}
}
}
[self.tableView reloadData];
}
I am a bit confused, though. When I filter this list using the textFieldShouldReturn and then return NO, it filters properly and does not crash. Something about returning YES from either one of these methods causes the crash after I have filtered. If I have not filtered at all, returning YES is no problem.
Let me know if there is any other code that I should post.
I have resolved the issue but I cannot (due to NDA) post the answer here yet. Those interested, and in the paid iOS developer program, should go to the NDA developer forums and search for UITextField EXC_BAD_ACCESS and you will find the answer...
in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
where is
return cell;
?
I think your UITextField searchfield is begin deallocated. If you use self.searchField to set your searchfield (assuming it's a retained property), that will solve it.
I'm not sure what the rest of your .h looks like. You could do:
#property (nonatomic, retain) UITextField *searchField;
Then in the .m:
#synthesize searchField;
That's what I mean by making search field a retained property. This way your class will keep the search field around.
In - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathreturn cell;
Donot release serachfield in the event;
Release in dealloc
add #property (nonatomic, retain) UITextField *searchField;

navigating between textfields of uitableview

I am making an coredata application in which I was instructed to make a tableview (filling form) with textfield in each row which I did successfully. Then I made a toolbar with previous and next button and add to textField's inputAccsoryView for navigating between the textfields of each cell. One textfield per row . I am also able to do the magic with previous and next button methods . Now the problem :
Suppose I have 3 sections . In first section 4 rows . In second section 6 rows and in the last section 1 row . Now when I start from the 1st row and presses next till the 11th row it is working properly but then I press next nothing happens as the first row is dequeued I get "nil" for it . The code I am using :
configuring the cell
if (cell == nil) {
NSLog(#"tag inside:%i",tag);
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:identifier] autorelease];
UITextField *theTextField = [[UITextField alloc] initWithFrame:CGRectMake(120, 10, 170, 25)];
theTextField.textAlignment = UITextAlignmentRight;
theTextField.delegate = self;
theTextField.tag = tag;
theTextField.inputAccessoryView = [self configureTheToolBar];
[theTextField setKeyboardAppearance:UIKeyboardAppearanceAlert];
[cell.contentView addSubview:theTextField];
[theTextField release];
}
cell.textLabel.text = rowLabel;
UITextField *textField = (UITextField *)[cell.contentView viewWithTag:tag];
textField.text = rowValue
I am providing tags for textfield like 601 ,602 etc .
Then getting the currentTextField tag
- (void)textFieldDidBeginEditing:(UITextField *)textField{
currentTextField = textField.tag;
}
then the next method
if(currentTextField == 611){
currentTextField = 601;
} else{
currentTextField = currentTextField + 1;
}
NSLog(#"current text fiedld = %i",currentTextField);
NSLog(#"text ; %#",[self cellForTag:currentTextField].textLabel.text);
UITextField *firstResponderField = (UITextField *) [[self cellForTag:currentTextField].contentView viewWithTag:currentTextField];
[firstResponderField becomeFirstResponder];
and the cellForTag method :
-(UITableViewCell *)cellForTag:(NSInteger)tag{
UITableViewCell *cell;
switch (tag) {
case 601:{
NSUInteger onlyRow[] = {0, 0};
NSIndexPath *onlyRowPath = [NSIndexPath indexPathWithIndexes:onlyRow length:2];
//[self.tableView scrollToRowAtIndexPath:onlyRowPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
cell = [self.tableView cellForRowAtIndexPath:onlyRowPath];
break;
}
return cell
this code is working partially as once off screen cells get out of memory I can't reach textfield in that cell and next button stops working till the currentTextfield value reaches to any visiblerow . What could be the solution . my stack is over flowed. :)
Ok this thread does the trick but I don't know how . can anyone explain me how ?
Once a cell goes off screen it will no longer be accessible. Because of this you might want to grab the values of your text fields as soon as the user has finished editing them by wiring up the UIControlEventEditingDidEnd event:
[myTextField
addTarget:self
action:#selector(myTextChanged:)
forControlEvents:UIControlEventEditingDidEnd];
In your myTextChanged function you can store the values away, perhaps in a dictionary if you want to keep them keyed against your tags.

UITableView section header and section footer not updating (redraw problem)

UPDATE 4.0
Seems like iOS 4.0 changed something here. Same code producing incorrect backgrounds for section header in the described scenario is working with 4.0 according to my first quick check!
Original
I have a UITableView grouped style with custom header and footer view. Inside the footer I put a UILabel and a UIButton.
Clicking on the button hides or show some rows, updates the UILabel in the footer view and finally resizes footer view.
Basically everything is working fine. BUT the text ion the label is not updated on the screen. It is updated in the UILabel text property, but only if I scroll the section footer out of the visible area and scroll it back, it is updated. So it's a typical redraw problem here of the UITableView.
I tried every method to force update like needsLayout etc. Nothing helped.
I have seen some related questions but with some different behaviour and no solution. Any help/ideas?
Thanks, Gerd
UPDATE:
My problems occurs with section footer, so here is my viewForFooterInSection.
Basically I want to collapse/expand a section, but not completely (that was an easy thing) instead only the empty cell (ItemSize empty). The footerView is large if it is collapsed and will shrink if it is expanded. Furthermore the label text will change.
- (UIView *)tableView: (UITableView *)tableView viewForFooterInSection: (NSInteger)section{
NSLog(#"viewForFooterInSection section:%i", section);
UIButton *myView;
UILabel *label;
if ([[[self.sectionStatus objectAtIndex:section] valueForKey:#"collapseStatus"] isEqual:#"collapse"]){
myView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 320, 52)];
[myView setBackgroundImage:[UIImage imageNamed:#"ItemViewFooter.png"] forState:UIControlStateNormal];
label = [[UILabel alloc] initWithFrame:CGRectMake(20, 32, 300, 20)];
label.text = NSLocalizedString(#"list_expand",#"");
} else { //is expanded
myView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 320, 21)];
[myView setBackgroundImage:[UIImage imageNamed:#"ListCollapseExpand.png"] forState:UIControlStateNormal];
label = [[UILabel alloc] initWithFrame:CGRectMake(20, 1, 300, 20)];
label.text = NSLocalizedString(#"list_collapse",#"");
}
myView.tag=section;
[myView addTarget:self action:#selector(collapseExpandAction:) forControlEvents:UIControlEventTouchUpInside];
myView.backgroundColor = [UIColor clearColor];
myView.adjustsImageWhenHighlighted = NO;
myView.showsTouchWhenHighlighted = YES;
label.textColor = FONTCOLOR;
label.font = [UIFont systemFontOfSize:14];
label.numberOfLines = 1;
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
[myView addSubview:label];
return myView;
};
In the button action method I store status of section collapse/expand and the number of displayed rows. Than I delete or insert rows. (It has to be with insert/delete because I need the animation).
- (void) collapseExpandSection: (NSInteger) section{
NSMutableArray *paths = [NSMutableArray arrayWithCapacity:10];
NSInteger row;
NSInteger numberOfDisplayedItems=[[[self.sectionStatus objectAtIndex:section] valueForKey:#"numberOfDisplayedRows"] intValue];
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
NSInteger numberOfAllItems=[sectionInfo numberOfObjects];
Item *tmpItem=nil;
NSSet *itemsWithSizes=nil;
//filter not used cells
for ( row = 0; row < numberOfAllItems; row++ ) {
tmpItem=[fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"itemSize != nil"];
NSSet *itemsWithSizes = [tmpItem.itemSizes filteredSetUsingPredicate:predicate];
if ([itemsWithSizes count]==0){
[paths addObject:[NSIndexPath indexPathForRow:row inSection:section]]; //all unused cells
};
}
if (numberOfDisplayedItems == numberOfAllItems){ //currently all shown => Collapse
[self.tableView beginUpdates];
[[self.sectionStatus objectAtIndex:section] setValue:[NSNumber numberWithInt:(numberOfDisplayedItems-[paths count])] forKey:#"numberOfDisplayedRows"];
[[self.sectionStatus objectAtIndex:section] setValue:#"collapse" forKey:#"collapseStatus"];
[self.tableView deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
} else { //Not all shown so expand with the unused cells
[[self.sectionStatus objectAtIndex:section] setValue:[NSNumber numberWithInt:(numberOfDisplayedItems+[paths count])] forKey:#"numberOfDisplayedRows"];
[[self.sectionStatus objectAtIndex:section] setValue:#"expand" forKey:#"collapseStatus"];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
}
return;
};
Doing all this works fine in general. After the blocks begin/endupdate the viewForFooter is called for every section and the label text is set correct in the property. However the display doesn't update correctly. As soon as a redisplay is forced (srolling out- scrolling in) the display is OK.
There 2 problems.
First problem is that section footer not updated.
Try call [tableView reloadData] or [tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationFade] after your update (may be with dalay).
Second problem is memory leaks in myView and label.
Also why do you use label when you can use button's internal label?
P.S. Don't allocate UIButton object directly because it is factory. Call [UIButton buttonWithType:UIButtonTypeCustom] instead.
Upd: Another way to update is to update footer directly by accessing footer views.
- (void) collapseExpandSection: (NSInteger) section{
Check that section is actualy your button
- (void) collapseExpandSection: (UIButton*) sender{
// Do update of sender here
// Do other stuff
}
Also you can try next trick: create UIView object in delegate, add your button and label on it and return instaed of buttom view itself.
My problem was that I was expanding the Section header to show a search bar, but it wouldn't redraw the view until I scrolled the UITableView.
I had my own SectionHeader class that subclassed UIView and controlled the searching stuff.
After my animation, I just used this to force an update. It's not pretty but it works.
CGPoint point = CGPointMake(((UIScrollView *)self.superview).contentOffset.x,
((UIScrollView *)self.superview).contentOffset.y+1);
[((UIScrollView *)self.superview) setContentOffset:point animated:NO];
point = CGPointMake(((UIScrollView *)self.superview).contentOffset.x,
((UIScrollView *)self.superview).contentOffset.y-1);
[((UIScrollView *)self.superview) setContentOffset:point animated:NO];
Basically force the UITableView to scroll down 1 pixel and up 1 pixel.
I had an issue just like this where I wanted to update the section header after inserting a new row. I found that calling tableView reloadSections() method with an animation setting of .None after I call the insertRows method worked for me (both calls in the same tableView update block). I got the insert animation I wanted and also the section header was updated.