SORU
17 Mayıs 2010, PAZARTESİ


navigationbar için Ekle düğmesini programlama yoluyla

Merhaba eğer tuşa basarsam bazı eylemleri gerçekleştirmek böylece o sağ tarafta, navigasyon bar, programlama yoluyla , düğmeye ayarlamak gerekiyor. , Programlama yoluyla navigasyon çubuğu oluşturduk

    navBar=[[UINavigationBar alloc]initWithFrame:CGRectMake(0,0,320,44) ];

Benzer şekilde, düğme eklemek istiyorum, bu gezinti çubuğunun sağ tarafında. Bunun için kullandım

  1. UIView* container = [[UIView alloc] init];
    
    // create a button and add it to the container
    UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 130, 44.01)];
    [container addSubview:button];
    [button release];
    
    // add another button
    button = [[UIButton alloc] initWithFrame:CGRectMake(160, 0, 50, 44.01)];
    [container addSubview:button];
    [button release];
    
    // now create a Bar button item
    UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:container];
    
    // set the nav bar's right button item
    self.navigationItem.rightBarButtonItem = item;
    [item release];
    
  2. UIImage *im;
    im=[UIImage imageNamed:@"back.png"];
    [button setImage:im forState:UIControlStateNormal];
    [im release];
    backButton = [[UIBarButtonItem alloc] initWithCustomView:button];       
    [backButton setImageInsets:UIEdgeInsetsMake(0, -10,5, 5)];
    [self.navigationItem setRightBarButtonItem:backButton];
    
  3. UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithTitle:@"button"               style:UIBarButtonItemStylePlain target:self action:@selector(refreshLogsAction:)];
    self.navigationItem.rightBarButtonItem = refreshItem;
    
    [refreshItem release];
    

Bütün bu yolları denedim, ama hiçbiri sağ tarafındaki düğmeye görüntülüyor.

CEVAP
16 Temmuz 2010, Cuma


Benim UİViewController türetilmiş sınıf içinde, şu iç viewDidLoad kullanıyorum:

UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] 
                               initWithTitle:@"Flip"                                            
                               style:UIBarButtonItemStyleBordered 
                               target:self 
                               action:@selector(flipView:)];
self.navigationItem.rightBarButtonItem = flipButton;
[flipButton release];

Bu yöntemi çağırır Başlığı Çevirin, sağ tarafında bir düğme ekler:

-(IBAction)flipView

Bu çok seviyorsun #3, ama benim kod içinde çalışıyor görünüyor.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Joshua Kywn

    Joshua Kywn

    17 Mayıs 2010
  • Maschine Tutorials

    Maschine Tut

    15 ŞUBAT 2011
  • TheSalband Rai

    TheSalband R

    11 NİSAN 2011