摘了自己的一部分代碼,寫在這裏
當每個cell的寬度都一樣的時候 可以使用xib,高度不一樣的時候要自定義Cell
在viewDidLoad方法中 創建FooterView和HeaderView,用loadNibNamed加載創建的xib,然後通過tableView的tableFooterView屬性,把創建的footerView賦給tableView 例:RCFooterView* footerView = [[[NSBundle mainBundle]loadNibNamed:@"RCFooterView" owner:niloptions:nil]firstObject]; self.tableView.tableFooterView = footerView;
在Cell的代理方法中,會用到獲取指定行索引等方法:
//創建索引(指定行的行號)
NSIndexPath *lastPath = [NSIndexPath indexPathForRow:self.tg.count -1 inSection:0];
//讓數據源對象重新加載數據"在指定行插入一行新的數據
[self.tableView insertRowsAtIndexPaths:@[lastPath]withRowAnimation:UITableViewRowAnimationAutomatic];
//讓cell滾動到最後一行
[self.tableView scrollToRowAtIndexPath:lastPathatScrollPosition:UITableViewScrollPositionBottom animated:YES];
點擊FooterView加載更過按鈕時 要用到一個延遲方法1,GCD
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 *NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if ([self.delegaterespondsToSelector:@selector(RCFooterViewButtonDidPush:)]) {
[self.delegate RCFooterViewButtonDidPush:self];
}
button.hidden = NO;
self.loadView.hidden = YES;
});
要想讓Activity控件轉起來 要把他的Animating屬性勾上