【发布时间】:2020-02-12 23:12:35
【问题描述】:
我无法在 Objective-c 上创建表格,因为我开始学习 Objective-c。
Google 帮不了我,我试过了。 希望你能帮到我
//更新:下面尼克显示了正确的答案。过了一段时间,我被提示回答这个问题,现在我可以和你分享答案。我想对像我这样的人有用
- (void)viewDidLoad
{
[super viewDidLoad];
//Here we initialize the table, create delegates and display it on the screen
arrData=[[NSArray alloc]initWithObjects:@"ONE",@"TWO",,@"THREE", nil];
tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
}
#pragma mark - UITableView DataSource & Delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return arrData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Cells initialization
static NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
cell.textLabel.text = [arrData objectAtIndex:indexPath.row];
return cell;
}
【问题讨论】:
-
例如看这个:appcoda.com/…
-
@Nick 对不起,我不知道如何投票赞成您的评论,我可以投票赞成答案。如果你会写答案,我会投赞成票:)
标签: ios objective-c xcode