我搜索得太多了,嘗試了很多想法,但我無法使它工作。自定義UITableCell不能正常工作
我有一個視圖控制器,並在該控制器我有一個tableview有自定義單元格。 我連接插座,數據源和委託,但是當我運行該項目,而不是我的自定義單元格。顯示UITableCell並且不顯示數據。這裏是我的.h和.m文件
#import <UIKit/UIKit.h>
@class SelectMutantCell;
@interface MutantViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>{
UITableView *tableView;
IBOutlet SelectMutantCell *mutantCell;
}
@property (nonatomic, weak) IBOutlet UITableView *tableView;
@property (nonatomic, weak) SelectMutantCell *mutantCell;
- (IBAction)cancel:(id)sender;
@end
,這裏是我的.m文件
@implementation MutantViewController
@synthesize tableView = _tableView;
@synthesize mutantCell = _mutantCell;
NSArray *mutants;
- (void)viewDidLoad
{
[super viewDidLoad];
//mutants = [mutants initWithObjects:@"Keko",@"HEHE",@"PEPE", nil];
UINib *cellNib = [UINib nibWithNibName:@"SelectMutantCell" bundle:nil];
[self.tableView registerNib:cellNib forCellReuseIdentifier:@"SelectMutantCell"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"SelectMutantCell";
SelectMutantCell *cell = (SelectMutantCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSLog(@"---");
cell.nameLabel.text = @"Hehe"];
cell.descriptionLabel.text = @"hhe";
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 3;
}
的的NSLog(@ 「---」)是調試和運行時出現。問題是在
cell.nameLabel.text = @"Hehe"];
cell.descriptionLabel.text = @"hhe";
這一塊,如果我寫cell.textLabel.text =「測試」它的工作原理,但我需要我的自定義單元格所示。
任何幫助將不勝感激..
確認SelectMutantCell.xib中的表視圖單元格實際上具有自定義類「SelectMutantCell」。 – 2012-08-03 11:18:06
http://oi50.tinypic.com/2hg4wpd.jpg在這裏你可以看到 – sftsz 2012-08-03 11:21:17