user2005257
user2005257

Reputation: 13

UITableView,numberOfRowsInSection

I have three data(date, view, textfield).I use SQLite(FMDB).and,It output to tableview. When you run this code, the same cell is output in all sections.I want to textfield and view in a cell for each date.I'm beginner,please tell me.

- (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;
}

Upvotes: 0

Views: 706

Answers (2)

ejazz
ejazz

Reputation: 2508

Select the right object in the array in the cellForRowAtIndexPath method:

- (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
}

Upvotes: 2

Madbreaks
Madbreaks

Reputation: 19529

Take a look at cellForRowAtIndexPath

Upvotes: 0

Related Questions