Я хочу задать вопрос о UITableView цели C. Я пишу программу, и я хотел бы создать UI программно. Однако я не знаю, как отобразить таблицу программно. У меня уже есть NSMutableArray, чтобы хранить отображенные данные. И я создаю объект UITableView *tableData;
, что я должен сделать для следующего шага?Большое спасибо.
после написания кода выше вы должны реализовать метод делегата UITableView.
это делегированный метод загрузки UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [your array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = [yourarray objectAtIndex:indexPath.row];
return cell;
}
Что-то вроде этого должно помочь (при условии, что он работает из вашего контроллера представления и у вас есть свойство, настроенное для табличного представления):
tableView = [[[UITableView alloc] initWithFrame:CGRectMake(...) style:UITableViewStylePlain] autorelease];
tableView.dataSource = self;
tableView.delegate = self;
[self.view addSubview:tableView];
Где вы заменяете CGRectMake (...)
с любым желаемым положением / размером.