Je bouton avoir du mal à ajouter à mon UITableViewCell
, la cellule a deux UILabel
s et deux UIImageView
s, parfois le UIImageView
contiendra une image et parfois un bouton:mon UITableViewCell bouton de réglage
dans mon UITableViewCell
sous-classe je:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
firstLock = [[UILabel alloc]init];
[firstLock setBackgroundColor:[UIColor clearColor]];
firstLock.textAlignment = UITextAlignmentLeft;
firstLock.font = [UIFont fontWithName:@"Arial-BoldMT" size:17];
secondLock= [[UILabel alloc]init];
[secondLock setBackgroundColor:[UIColor clearColor]];
secondLock.textAlignment = UITextAlignmentRight;
secondLock.font = [UIFont fontWithName:@"Arial-BoldMT" size:17];
firstLockImage = [[UIImageView alloc]init];
secondLockImage = [[UIImageView alloc] init];
[self.contentView addSubview:firstLock];
[self.contentView addSubview:secondLock];
[self.contentView addSubview:firstLockImage];
[self.contentView addSubview:secondLockImage];
}
return self;
}
lorsque l'un des UIImageView
s est juste une image pas de problème, mais il se bloque lorsque je ajoutez un UIButton
(imagé) en tant que sous-vue.
Dans la mise en œuvre UITableViewDataSource
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImage *btnImage = [UIImage imageNamed:@"bike_ok.png"];
UIButton *button =[UIButton alloc];
[button setImage:btnImage forState:UIControlStateNormal];
[cell.secondLockImage addSubview:button];
Ajout d'un bouton comme sous-vue de la vue de l'image se bloque:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Requesting the window of a view (<UIButton: 0x7bac7d0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = (null)>) with a nil layer. This view probably hasn't received initWithFrame: or initWithCoder:.'
*** First throw call stack:
Qu'est-ce que je manque?
Merci!
Ajoutez juste! Parce que le UIImageView a NON par défaut et le bouton ne fonctionne pas sans cela!
Am J'ai raté quelque chose? Je ne vois pas où vous créez (et réutilisez) la cellule elle-même dans votre code. L'action généralement effectuée dans tableView: cellForRow: – Leonardo
Je ne fais que copier le code correspondant – user1256477