gpt4 book ai didi

ios - 使用字符串数组填充 UI TableView

转载 作者:行者123 更新时间:2023-11-28 20:02:12 25 4
gpt4 key购买 nike

我在任何地方都找不到简单明了的答案,而且我拒绝相信 XCode 会像我在那里找到的其他教程一样让事情变得困难...

假设我有以下数组

NSArray* 天数 = [NSArray arrayWithObjects:@"Sunday",@"Monday",@Tuesday",@"Wednesday",@"Thursday",@"Friday",@"Saturday",nil] ;

我有一个 UI TableView ,table_Days,我想简单地显示数组中的项目。填充表格的正确方法是什么?

最佳答案

以下是我的完整解释,从一个与您极其相​​似的案例开始:

http://www.apeth.com/iOSBook/ch21.html#_table_view_data

假设 days 存储为实例变量,可通过属性 self.days 访问。然后将 self 设置为 TableView 的 datasource 并使用此代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (!self.days) // data not ready?
return 0;
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.days count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:@"Cell"
forIndexPath:indexPath];
cell.textLabel.text = (self.days)[indexPath.row];
return cell;
}

关于ios - 使用字符串数组填充 UI TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23480697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com