1.必需设置以下三个方法,返回不能为“0”,显示几“组”数据:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.friends.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ID = @"ContactCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
//获取对应的好友
XMPPUserCoreDataStorageObject *friend = self.friends[indexPath.row];
cell.textLabel.text = friend.jidStr;
return cell;
}
2.有的不需要设置代理,有的需要设置代理才行,下面是设置代理:
.h文件:
#import <UIKit/UIKit.h>
@interface WCContactsViewController : UITableViewController<UITableViewDataSource,UITableViewDelegate>
@end
.m文件:
- (void)viewDidLoad {
[super viewDidLoad];
self.friendsTableView.dataSource = self;
self.friendsTableView.delegate = self;
//从数据库加载好友列表显示
[self loadFriends];
[self.friendsTableView reloadData];
}