簡體   English   中英

如何在UITableview中動態地將行插入n個節

[英]How to insert row to n number of sections dynamically in UITableview

如何更新中的行數

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ }

展開時將增加行數。

`-(void)rotationButtonToExpanded:(UIButton *)aButton部分:(int)aSection {

// Rotate the button with animation.
[UIView beginAnimations:ROTATE_TO_EXPAND context:nil];
[UIView setAnimationDuration:ANIMATION_DURATION];
aButton.transform = CGAffineTransformMakeRotation(M_PI*2.5);
[UIView commitAnimations];

// Save the state (expanded or collapsed) of button with index path as key.
BOOL isExpanded=![[mStateOfNodes objectAtIndex:aSection] isExpanded];
[[mStateOfNodes objectAtIndex:aSection] setIsExpanded:isExpanded];

NSArray*theDataOfChildCells=[[self.mNodes objectAtIndex:aSection] valueForKey:CHILD_NODES];


for (int i=0; i<theDataOfChildCells.count; i++) {
    mNumberOfCells++;

    [self beginUpdates];
    NSIndexPath*theIndexPath=[NSIndexPath indexPathForRow:i inSection:aSection];
    [self insertRowsAtIndexPaths:[NSArray arrayWithObject:theIndexPath] withRowAnimation:UITableViewRowAnimationMiddle];
    [self endUpdates];

}

}`

使用的重載數據方法

[self.tableview reloadData];

使用以下代碼用於在UITable添加具有特定行和部分的行

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowNO inSection:SectionNO];
        [self.tblView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        rowNO=rowNO+1;
     [self.tblView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
        [self.tblView reloadData];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM