2013-01-23 22 views
0

У меня есть три данных (дата, представление, текстовое поле). Я использую SQLite (FMDB) .and, Он выводится в tableview. Когда вы запускаете этот код, одна и та же ячейка выводится во всех разделах. Я хочу текстовое поле и просмотр в ячейке для каждой даты. Я начинаю, пожалуйста, скажите мне.UITableView, numberOfRowsInSection

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

Хм, я не могу. – user2005257

ответ

2

Выберите нужный объект в массиве в методе 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 
} 
+0

спасибо. Я пробую ваш совет. – user2005257

Смежные вопросы