iphone - UITableView, numberOfRowsInSection

标签 iphone ios xcode

我有三个数据(日期、 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/

相关文章:

ios - 如何检查以下响应中是否存在数据 key ?

ios - 检测在 UIScrollView 中点击 UIImageView

ios - 'locationManager(_:didUpdateLocations:)' 的参数具有与协议(protocol) 'CLLocationManagerDelegate' 预期不同的可选性

iOS 框架不适用于模拟器

ios - 导航栏中的分段控件

iphone - popViewController 不工作

iphone - Apple 是否允许监控跳板事件?

iphone - 屏幕锁定时,本地通知不起作用

ios - 对于 iOS 8 和 iOS 9 中的某些特定范围,NSMutableAttributedString 不显示不同颜色的字符串

ios - PayPal iOS 模拟器应用程序接受无效密码