Gaojian922188
Gaojian922188

Reputation: 503

uitabview delegate method never called

I have a subclass of uiviewcontroller,and implemented the delegate UITableViewDelegate and UITableViewDataSource.my code like:

- (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;
}

I have set the breakpoints,and the delegate method is never called.what's the problem?

Upvotes: 0

Views: 104

Answers (1)

jbat100
jbat100

Reputation: 16827

You need to set the tableView delegate and data source to self

tableView.delegate = self;
tableView.dataSource = self;

and implement the method (returning at least 1)

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

Upvotes: 1

Related Questions