1. - (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section 2. {
3. if (section == 0) 4. { 5.
6. UIView* header = [[[NSBundle mainBundle] loadNibNamed: @\7. owner: self
8. options: nil] lastObject]; 9. 10. else 11. {
12. return nil; 13. } 14. }
- (UIView *)tableView:(UITableView *)tableView view{if (section == 0) {UIView* header = [[[NSBundle mainBu else { return nil; }} (8) - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 当用户选中某个行的cell的时候,回调用这个。但是首先,必须设置tableview的一个属性为可以select 才行。 [cpp]view plaincopyprint? 1. TableView.allowsSelection=YES;
TableView.allowsSelection=YES; [cpp]view plaincopyprint? 1. cell.selectionStyle=UITableViewCellSelectionStyleBlue;
cell.selectionStyle=UITableViewCellSelectionStyleBl 如果不希望响应select,那么就可以用下面的代码设置属性: [cpp]view plaincopyprint? 1. TableView.allowsSelection=NO;
TableView.allowsSelection=NO; 下面是响应select 点击函数,根据哪个section,哪个row 自己做出响应就好啦。 [cpp]view plaincopyprint? 1. - (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath 2. {
3. if (indexPath.section == 1) 4. { 5. return; 6. }
7. else if(indexPath.section==0) 8. {
9. switch (indexPath.row) 10. { 11. //聊天 12. case 0: 13. {
14. [self onTalkToFriendBtn]; 15. } 16. break; 17.
18. default: 19. break; 20. } 21. }
22. else 23. { 24. return ; 25. } 26. 27. }
- (void)tableView:(UITableView *)tableView didSelec{if (indexPath.section == 1) {return;}else if(indexPath.section==0){switch (indexPath.row) {//聊天case 0:{[self onTalkToFrie}break;default: 如何让cell 能够响应 select,但是选中后的颜色又不发生改变呢,那么就设置 cell.selectionStyle = UITableViewCellSelectionStyleNone; [cpp]view plaincopyprint? 1. - (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath 2. {
3. //cell被选中后的颜色不变
4. cell.selectionStyle = UITableViewCellSelectionStyleNone; 5. }
- (UITableViewCell *)tableView:(UITableView *)table{ //cell被选中后的颜色不变 cell.selectionStyle = UITableViewCellSelectionS} (9)如何设置tableview 每行之间的分割线 [cpp]view plaincopyprint? 1. self.tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
self.tableView.separatorStyle=UITableViewCellSepara 如果不需要分割线,那么就设置属性为 UITableViewCellSeparatorStyleNone 即可。 (10)如何设置 tableview cell的背景颜色 [cpp]view plaincopyprint? 1. - (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath 2. {
3. //设置背景颜色
4. cell.contentView.backgroundColor=[UIColor colorWithRed:0.957 green:0.957
blue:0.957 alpha:1];