2012-04-11 16 views
6

मैं आईओएस विकास के लिए नया हूं। मैंने अपने आईपैड एप्लिकेशन व्यू में नेविगेशन बार बनाया है। मुझे नेविगेशन नियंत्रक की आवश्यकता नहीं है इसलिए मैंने केवल नेविगेशन बार जोड़ा है। अब मैं उस नेविगेशन बार में बटन जोड़ना चाहता हूं। मैंने बहुत कोशिश की लेकिन कोई सफलता नहीं मिली। क्या बटन के साथ केवल नेविगेशन बार जोड़ना संभव है? यदि हां तो मुझे कुछ नमूना कोड सुझाएं।नेविगेशन नियंत्रक के बिना नेविगेशन बार में बार बटन कैसे जोड़ें।

"मेरे पास नेविगेशन नियंत्रक नहीं है या इसकी आवश्यकता है। मैं केवल एक दृश्य में नेविगेशन बार जोड़ना चाहता हूं।"

Bellow मेरी कोड है जो मैं viewDidLoad()

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 1026, 50)]; 
[navBar setTintColor:[UIColor blackColor]]; 
[navBar setDelegate:self]; 
[self.view addSubview:navBar]; 

अग्रिम धन्यवाद में नेविगेशन पट्टी को जोड़ने के लिए लिखना .... है

उत्तर

1

इस प्रकार आप नेविगेशन पट्टी करने के लिए बटन जोड़ सकते हैं:

UIBarButtonItem *btnSave = [[UIBarButtonItem alloc] 
           initWithTitle:@"Save" 
           style:UIBarButtonItemStyleBordered 
           target:self 
          action:@selector(save_Clicked:)]; 
navBar.rightBarButtonItem = btnSave; 
[btnSave release]; 

UIBarButtonItem *btnCancel = [[UIBarButtonItem alloc] 
           initWithTitle:@"Cancel"          
           style:UIBarButtonItemStyleBordered 
           target:self 
           action:@selector(cancel_Clicked:)]; 
navBar.leftBarButtonItem = btnCancel; 
[btnCancel release]; 
+2

उपरोक्त कोड में यह लाइन मुझे त्रुटि देती है। 'navBar.rightBarButtonItem = btnSave; ' त्रुटि: अर्थपूर्ण समस्या: संपत्ति' rightBarButtonItem 'प्रकार' UINavigationBar * ' –

+0

की वस्तु पर नहीं मिली है, आप xib फ़ाइल में नेविगेशन बार भी जोड़ सकते हैं, फिर आप इसमें बार बटन आइटम जोड़ सकते हैं। –

5
UIBarButtonItem *bi1 = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(editButton)]; 

bi1.style = UIBarButtonItemStyleBordered; 
bi1.tintColor = [UIColor colorWithWhite:0.305f alpha:0.0f]; 

self.navigationItem.rightBarButtonItem = bi1; 

[bi1 release]; 
11

मैंने इंटरफ़ेस बिल्डर का उपयोग एक स्थिर तालिका बनाने के लिए किया है UITableViewController में देखें। यह UITableViewController सामान्य रूप से दिखाया गया है। फिर मैंने इसके पीछे UINavigationController के बिना एक नेविगेशनबार जोड़ा:

//Creating the plain Navigation Bar 
UINavigationBar *headerView = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 

//The UINavigationItem is neede as a "box" that holds the Buttons or other elements 
UINavigationItem *buttonCarrier = [[UINavigationItem alloc]initWithTitle:@"Sign-In"]; 

//Creating some buttons: 
UIBarButtonItem *barBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Zurück" style:UIBarButtonItemStyleDone target:self action:@selector(signInBackPressed:)]; 
UIBarButtonItem *barDoneButton = [[UIBarButtonItem alloc] initWithTitle:@"Fertig" style:UIBarButtonItemStylePlain target:self action:@selector(signInDonePressed:)]; 

//Putting the Buttons on the Carrier 
[buttonCarrier setLeftBarButtonItem:barBackButton]; 
[buttonCarrier setRightBarButtonItem:barDoneButton]; 

//The NavigationBar accepts those "Carrier" (UINavigationItem) inside an Array 
NSArray *barItemArray = [[NSArray alloc]initWithObjects:buttonCarrier,nil]; 

// Attaching the Array to the NavigationBar 
[headerView setItems:barItemArray]; 

// Adding the NavigationBar to the TableView 
[self.tableView setTableHeaderView:headerView]; 

मुझे उम्मीद है कि यह किसी की मदद करेगा!

संबंधित मुद्दे