我有一个uiviewcontroller的子类,并实现了委托UITableViewDelegate和UITableViewDataSource.my代码,如:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
_listname=[[NSMutableArray alloc]initWithObjects:@"cu",@"al",@"zn",@"au",@"ru",@"fu",@"rb",@"pb",@"wr", nil];
}
- (void)dealloc
{
[super dealloc];
}
#pragma mark -
#pragma mark Table View Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
[tableView setSeparatorColor:[UIColor clearColor]];
return [_listName count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return TABLE_HEIGHT;
}
我设置了断点,并且从不调用委托方法。问题是什么?
答案 0 :(得分:1)
您需要将tableView委托和数据源设置为self
tableView.delegate = self;
tableView.dataSource = self;
并实现该方法(至少返回1)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView