Objective c 带选项卡栏控制器的UITableView

Objective c 带选项卡栏控制器的UITableView,objective-c,uitableview,Objective C,Uitableview,我有一个选项卡栏控件,我想在第一个选项卡中显示表视图 在我的故事板中,我有带项目的选项卡栏视图控制器,我将tableview和tableview单元格放在其中。(我不确定。我应该让它们在tableview中显示数据,还是以编程方式显示数据?)我从数据库中获取数据(这方面没有任何问题),但无法绑定tableview中的数据 我的代码有什么问题 我的代码: .h文件 @interface CategoryTabController : UIViewController<UITable

我有一个选项卡栏控件,我想在第一个选项卡中显示表视图

在我的故事板中,我有带项目的选项卡栏视图控制器,我将tableview和tableview单元格放在其中。(我不确定。我应该让它们在tableview中显示数据,还是以编程方式显示数据?)我从数据库中获取数据(这方面没有任何问题),但无法绑定tableview中的数据

我的代码有什么问题

我的代码:

.h文件

     @interface CategoryTabController : UIViewController<UITableViewDataSource, UITableViewDelegate>
    {
        DatabaseProcess *databaseProcess;
        UITableView *categoryTableView;
        NSMutableArray *categoryTableArray;

    }

.m file

@implementation CategoryTabController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    databaseProcess = [[DatabaseProcess alloc]init];

    //Get Category data to array
    categoryTableArray = [[NSMutableArray alloc]initWithArray:[databaseProcess getAllActiveCategory]];


    categoryTableView = [[UITableView alloc]init];

    categoryTableView.delegate = self;
    categoryTableView.dataSource = self;

    [self.view addSubview: categoryTableView];


}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{    // Return the number of rows in the section.
    return categoryTableArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CategoryCell" forIndexPath:indexPath];

    cell.textLabel.text = [categoryTableArray objectAtIndex: indexPath.row];

    return cell;
}
@接口类别选项卡控制器:UIViewController
{
DatabaseProcess*DatabaseProcess;
UITableView*类别TableView;
NSMutableArray*categoryTableArray;
}
.m文件
@实现类别选项卡控制器
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后执行任何其他设置。
databaseProcess=[[databaseProcess alloc]init];
//将类别数据获取到数组
categoryTableArray=[[NSMutableArray alloc]initWithArray:[databaseProcess getAllActiveCategory]];
categoryTableView=[[UITableView alloc]init];
categoryTableView.delegate=self;
categoryTableView.dataSource=self;
[self.view addSubview:categoryTableView];
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
//返回节数。
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{//返回节中的行数。
返回categoryTableArray.count;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:@“CategoryCell”forIndexPath:indexPath];
cell.textLabel.text=[categoryTableArray objectAtIndex:indexPath.row];
返回单元;
}

您必须将categoryTableView设置为IBOutlet属性,并将其连接到IB中的表。此外,您还必须将“CategoryCell”设置为IB中的单元格标识符,使其“dequeueReusableCellWithIdentifier”起作用