i have make a custom cell i开发者_JAVA百科n nib file with delegate.
I have define a .h and .m for custom cell:
@interface InscriptionCustomCell : UITableViewCell {
IBOutlet UILabel *titreCell;
IBOutlet UITextField *contenuCell;
}
@property(nonatomic,retain) UILabel *titreCell; @property(nonatomic,retain) UITextField *contenuCell;
@end
And when I try to use it with my tableView:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"InscriptionCustomCell";
InscriptionCustomCell *cell = (InscriptionCustomCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//[cell.textLabel setText:@"Cell"];
// Configure the cell...
if(indexPath.section ==0)
{
[cell.titreCell setText:[model.listModuleInfoPerso objectAtIndex:indexPath.row]];
[cell.contenuCell setPlaceholder:[model.listModuleInfoPerso objectAtIndex:indexPath.row]];
}else {
[cell.titreCell setText:[model.listModuleInfoSupp objectAtIndex:indexPath.row]];
[cell.contenuCell setPlaceholder:[model.listModuleInfoSupp objectAtIndex:indexPath.row]];
}
return cell;
}
I have an error:
reason: '-[UITableViewCell titreCell]: unrecognized selector sent to instance 0x4b5f430'
Why? My custom cell is own statement!
This is wrong:
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
You are creating a UITableViewCell instance not your custom cell.
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyCell"owner:self options:nil];
cell = [nib objectAtIndex:0];
}
精彩评论