1

我一直在制作这样的应用程序。

BooksViewController
↑↓
EditViewController

SQL:books (id INTEGER PRIMARY KEY AUTOINCREMENT, author TEXT, title TEXT, copyright TEXT, category TEXT)

我用xib自定义了TableViewCell。
cell.label1.text = book.title;
cell.label2.text = book.copyright;
cell.label3.text = book.category;
但是数据并没有反映在 TableViewCell 上。


我有这个代码。

BooksViewController

    #import "BooksCell.h"
    //////
            - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString* CellIdentifier = @"BooksCell";

        BooksCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if( cell == nil )
        {
            cell = [[[BooksCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }

        Book* book = [self bookAtIndexPath:indexPath];
        cell.label1.text = book.title;
        cell.label2.text = book.copyright;
        cell.label3.text = book.category;

        return cell;
    }

编辑视图控制器

- (IBAction)saveData:(id)sender
{    
    Book* newBook = [[Book alloc] init];
    newBook.bookId    = self.book.bookId;
    newBook.title     = _titleTextField.text;
    newBook.author    = _authorTextField.text;
    newBook.copyright    = _copyrightTextField.text;
    newBook.category    = _categoryTextField.text;

    if( self.book )
    {
        [self.delegate editBookDidFinish:self.book newBook:newBook];
    }
    else
    {
        [self.delegate addBookDidFinish:newBook];
    }
}

BooksCell.h

    #import <UIKit/UIKit.h>

@interface BooksCell : UITableViewCell{
    UILabel* label1;
    UILabel* label2;
    UILabel* label3;
}

@property (nonatomic, retain) IBOutlet UILabel* label1;
@property (nonatomic, retain) IBOutlet UILabel* label2;
@property (nonatomic, retain) IBOutlet UILabel* label3;

@end



单元格为空白。
但是当我描述

cell.textLabel.text = book.title; 

在方法 [cellForRowAtIndexPath] 中,标题正确显示在单元格中。
关于如何修复它的任何想法?

4

0 回答 0