Question

Je crée une vue personnalisée à droite comme suit:

// Build the Segmented Control
NSArray *segmentTextContent = [NSArray arrayWithObjects:[UIImage imageNamed:@"arrow-dice.png"], [UIImage imageNamed:@"arrow-up.png"], [UIImage imageNamed:@"arrow-down.png"], nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];

// Customize the Segmented Control
segmentedControl.momentary = YES;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[segmentedControl addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];

Alors je l'ajoute à ma barre de navigation comme suit:

// Add the control to the navigation bar right item
UIBarButtonItem *segmentItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segmentItem;
self.navigationItem.rightBarButtonItem.title = @"";
[segmentItem release];

Je peux le cacher comme suit:

self.navigationItem.rightBarButtonItem.customView.hidden = NO;

QUESTION ... mais comment puis-je désactiver tous (ou mieux, un élément spécifique) du contrôle segmenté?

Ce qui suit ne fonctionne pas.

self.navigationItem.rightBarButtonItem.enabled = NO;

Toutes les idées ont apprécié ...

Merci,
mat

Était-ce utile?

La solution

UISegmentedControl.h

- (void)removeSegmentAtIndex:(NSUInteger)segment animated:(BOOL)animated;
- (void)removeAllSegments;
- (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)segment;       //default is YES

  e.g. [segmentedControl setEnabled:NO forSegmentAtIndex:1];

Hope qui aide

Autres conseils

[navItem.rightBarButtonItem setEnabled:NO];

aussi simple que cela:)

Référence: http: // développeur .apple.com / bibliothèque / ios / # documentation / UIKit / référence / UIBarItem_Class / référence / Reference.html Voir activé propriété.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top