我一直在制作这样的应用程序。
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;
}
EditViewController
- (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]中,标题正确显示在单元格上
我对如何解决问题有任何想法?