{"id":691,"date":"2012-10-19T07:22:27","date_gmt":"2012-10-19T06:22:27","guid":{"rendered":"http:\/\/www.any-where.de\/blog\/?p=691"},"modified":"2012-10-19T07:26:19","modified_gmt":"2012-10-19T06:26:19","slug":"adding-multiple-buttons-to","status":"publish","type":"post","link":"https:\/\/www.any-where.de\/blog\/adding-multiple-buttons-to\/","title":{"rendered":"Adding multiple buttons to UINavigationItem"},"content":{"rendered":"<p>I recently needed to add several buttons to a UINavigationItem in my iOS 6 app. All documentation I found only spoke about the standard buttons on a UINavigationItem which are backBarButtonItem, leftBarButtonItem and rightBarButtonItem. Well, not enough for me: I needed 2 buttons to be displayed on the left side of my navigation.<\/p>\n<p>After hours of searching, reading and trying I found this. Maybe somebody else might need it, too:<\/p>\n<blockquote style=\"width:459px; overflow:auto\">\n<div style=\"width:1600px\">\n<p>NSMutableArray *buttons = [[NSMutableArray alloc]initWithCapacity:2];<\/p>\n<p>UIBarButtonItem *button1 = [[UIBarButtonItem alloc]initWithTitle:@&#8221;button1&#8243; style:UIBarButtonItemStylePlain target:self action:@selector(myLittleAction)];<br \/>\nUIBarButtonItem *button2 = [[UIBarButtonItem alloc]initWithTitle:@&#8221;button2&#8243; style:UIBarButtonItemStylePlain target:self action:@selector(myOtherAcion)];<\/p>\n<p>[buttons addObject:button1];<br \/>\n[buttons addObject:button2];<br \/>\n[self.navigationItem setLeftBarButtonItems:buttons];\n<\/p><\/div>\n<\/blockquote>\n<p>So easy and yet it took me so long to set up&#8230; \ud83d\ude42<\/p>\n<p>With this approach you lose the standard back button for navigation. But there&#8217;s help. In the method myLittleAction I did this:<\/p>\n<blockquote style=\"width:459px; overflow:auto\">\n<div style=\"width:1600px\">\n<p>    UIViewController *prevVC = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2];<br \/>\n    [self.navigationController popToViewController:prevVC animated:YES];<\/p>\n<\/div>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I recently needed to add several buttons to a UINavigationItem in my iOS 6 app. All documentation I found only spoke about the standard buttons on a UINavigationItem which are backBarButtonItem, leftBarButtonItem and rightBarButtonItem. Well, not enough for me: I needed 2 buttons to be displayed on the left side of my navigation. After hours &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.any-where.de\/blog\/adding-multiple-buttons-to\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Adding multiple buttons to UINavigationItem&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[207,4],"tags":[208,209],"class_list":["post-691","post","type-post","status-publish","format-standard","hentry","category-ios","category-programming-the-web","tag-ios-2","tag-uinavigationitem"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.any-where.de\/blog\/wp-json\/wp\/v2\/posts\/691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.any-where.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.any-where.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.any-where.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.any-where.de\/blog\/wp-json\/wp\/v2\/comments?post=691"}],"version-history":[{"count":10,"href":"https:\/\/www.any-where.de\/blog\/wp-json\/wp\/v2\/posts\/691\/revisions"}],"predecessor-version":[{"id":701,"href":"https:\/\/www.any-where.de\/blog\/wp-json\/wp\/v2\/posts\/691\/revisions\/701"}],"wp:attachment":[{"href":"https:\/\/www.any-where.de\/blog\/wp-json\/wp\/v2\/media?parent=691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.any-where.de\/blog\/wp-json\/wp\/v2\/categories?post=691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.any-where.de\/blog\/wp-json\/wp\/v2\/tags?post=691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}