开发者

uitabview delegate method never called

开发者 https://www.devze.com 2023-04-12 21:17 出处:网络
I have a subclass of uiviewcontroller,and implemented the delegate UITableViewDelegate and UITableViewDataSource.my code like:

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=[[NSMutableAr开发者_如何学Goray 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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号