2011-05-26 4 views
1

Je suis capable de créer un tableview avec textlabel et avec detaillabeltext.Comment placer UIButton dans la cellule uitableview?

En plus de cela, est-il possible d'ajouter UIButton dans la cellule.

Je veux dire après la detaillabeltext, puis-je placer un UIButton (comme "Supprimer")

i ont actuellement le code suivant

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
//----------------------------------------------------------------------------------------------------- 
{ 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    profileName = [appDelegate.sentItemsList objectAtIndex:indexPath.row]; 

    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 

     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 

    NSString *subjectData = [profileName.sent_subject stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; 

    cell.textLabel.text = [NSString stringWithFormat: @"%@ ", subjectData]; 

    cell.textLabel.font = [UIFont boldSystemFontOfSize:13]; 


    NSString *CompanyName = [profileName.sent_content stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; 

    cell.detailTextLabel.text = [NSString stringWithFormat: @"%@ ",CompanyName]; 

    cell.detailTextLabel.font = [UIFont systemFontOfSize:10]; 

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 

    cell.backgroundColor = [UIColor colorWithRed:230.0/255.0 green:249.0/255.0 blue:230.0/255.0 alpha:2.0]; 

    return cell; 
} 

Merci pour votre temps et aide!

+0

double possible de [UIButton dans la cellule UITableView comme "Supprimer l'événement"] (http://stackoverflow.com/questions/1076785/uibutton-in-uitableview- cell-like-delete-event) –

+0

Pour quoi faire, vous voulez ajouter le bouton? Comme si vous vouliez implémenter une fonctionnalité de suppression, vous pouvez utiliser un accessoire, sinon vous devrez implémenter chaque chose comme une sous-vue de votre cellule de vue de table. – rptwsthi

+0

@rptwsthi: pas comme la fonctionnalité de suppression. je veux appeler mon "ajouter aux favoris" bouton – user198725878

Répondre

6
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button addTarget:self action:@selector(aMethod:) 
forControlEvents:UIControlEventTouchDown]; 
[button setTitle:@"Show View" forState:UIControlStateNormal]; 
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); 
[cell addSubview:button]; 
+0

c'est une bonne solution, mais il va cacher tout le texte antérieur (étiquette et sous-étiquette) – rptwsthi

+0

non il ne sera pas cacher les précédents ... donner les cooridés correctement – Aravindhan

+1

@rptwsthi : sinon, vous pouvez voir ce tutoriel, il est bon http://www.e-string.com/content/custom-uitableviewcells-interface-builder – Aravindhan

2

Vous pouvez ajouter un bouton ou tout autre contrôle à la vue du contenu de la cellule.

UIButton *cellButton = [[UIButton alloc]init]; 
[cellButton addTarget:self action:@selector(uploadData:)forControlEvents:UIControlEventTouchDown]; 
[cellButton setTitle:@"Upload Now" forState:UIControlStateNormal]; 
cellButton.frame = CGRectMake(100, 180, 150, 35); 
[cell.contentview addSubview:cellButton]; 
[cellButton release]; 

Ajouter un contrôle à afficher le contenu de la cellule

Questions connexes