J'essaie de mettre un UIButton
à l'intérieur d'un UITableViewCell
.Mettez un UIButton dans un UITableView
Le UITableView
a également des cellules contenant UILabels
et les cellules ont des arrière-plans de gradient qui y sont attirés. Le problème que je vois est que mon UIButton
est juste une cellule noire pleine sans affichage de texte, et changer les propriétés de couleur et de couleur de fond ne semble rien faire.
Voici le code que j'utilise pour créer le bouton:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"InAppViewController, doing this - width= %f", self.wdth);
static NSString *ProductTableIdentifier = @"ProductTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ProductTableIdentifier];
if (cell == nil)
{
if (self.wdth >= 700) {
CGRect cellFrame = CGRectMake(0, 0, (self.wdth - 100), 40);
cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier: ProductTableIdentifier] autorelease];
// Set up some labels...
CGRect seenValueRect = CGRectMake(self.wdth-320, 0, 100, 40);
UIButton *seenValue = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[seenValue setBackgroundColor:[UIColor greenColor]];
seenValue.tag = kSeenValueTag;
seenValue.frame = seenValueRect;
[seenValue setTitle:@"I'm a clone" forState:UIControlStateNormal];
[cell.contentView addSubview:seenValue];
[seenValue release];
// Continue setting up cell...
Le lien pastebin contient le code à la fonction cellForRowAtIndexPath()
entière (pour la UITableView
en question).
Jetez un coup d'œil à la section * Customizing Cells * de la documentation iOS 'UITableView': http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/ TableViewCells/TableViewCells.html –