gpt4 book ai didi

iphone - UITableView, numberOfRowsInSection

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

我有三个数据(日期、 View 、文本字段)。我使用 SQLite(FMDB)。并且,它输出到 TableView 。当您运行此代码时,所有部分都会输出相同的单元格。我想在每个日期的文本字段和单元格中查看。我是初学者,请告诉我。

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

titleArry = [[NSMutableArray alloc] init ]; //タイトルを格納するための可変配列
dateArray = [[NSMutableArray alloc] init ]; // 日付格納する可変配列
contentsArry = [[NSMutableArray alloc] init ]; //画像を格納するための可変配列


[DataModel selectTitle:titleArry];
[DataModel selectDateTitle:dateArray];
[DataModel selectContents:contentsArry];

NSMutableSet *mutableSet = [NSMutableSet setWithArray:dateArray]; // 日付の重複を取り除く
array = [mutableSet allObjects];

[table reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return array.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return contentsArry.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
}

//セルに表示する内容
cell.textLabel.text = [titleArry objectAtIndex:indexPath.row];
cell.imageView.image = [[UIImage alloc] initWithData:[contentsArry objectAtIndex:indexPath.row]];

return cell;
}

最佳答案

cellForRowAtIndexPath 方法中选择数组中的正确对象:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//get the right object (use the object that is in the array, this is just an example)
NSObject *object = [array objectAtIndex:indexPath];
cell.textLabel.text = object.title
}

关于iphone - UITableView, numberOfRowsInSection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14489028/

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