1
나는 탭 막대 컨트롤을 가지고 있으며 첫 번째 탭에 테이블보기를 표시하려고합니다.Tab Bar Controller가있는 UITableView
내 스토리 보드에는 Items가있는 Tab Bar보기 컨트롤러가 있으며 tableview 및 tableview 셀을 넣습니다. (나는 그것에 대해 확실하지 않습니다. 나는 그들을 테이블 뷰에 데이터를 표시해야합니까 또는 프로그래밍 방식으로해야합니까?) 데이터베이스에서 데이터를 가져 오는 중이 야 (이 측면에서 어떤 문제가 없습니다) 있지만 tableview 데이터를 바인딩 할 수 없습니다. .
내 코드가 잘못 되었나요?
내 코드 :
.H 파일 당신은 함께 IBOutlet 속성으로 categoryTableView을하고 IB에서 테이블에 연결해야합니다
@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;
}
Marat에게 도움을 주셔서 감사합니다. 그것은 효과가 있었다. – Arda