UIView 中应用
在.h文件中添加<UITableViewDataSource,UITableViewDelegate>
需分配UITableView
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 150, 1004)style:UITableViewStylePlain];
tableView.dataSource = self;
tableView.delegate =self;
[self addSubview:tableView];
通过下两个基本方法对其初始化
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
在xib或者MainStoryboard中已添加了UITableView,则需右键把delegate和datasource添加到相关View中。
再通过下两个基本方法对其初始化
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;