2013-08-04 50 views
0

我試圖在我的應用中創建一個彈出式菜單,就像facebook應用使用的一樣。創建不帶導航欄按鈕的彈出菜單

我發現這個非常好的教程,並得到它在他們的例子中工作。 http://www.appcoda.com/ios-programming-sidebar-navigation-menu/

在他們的示例中,他們使用導航欄上的導航欄項作爲激活和取消激活彈出菜單的按鈕。

在我目前的項目中,我不想使用導航欄,並希望只有一個按鈕來激活彈出菜單。

但是,當涉及到下面的一段代碼時,我不會做什麼。

// Set the side bar button action. When it's tapped, it'll show up the sidebar. 
_sidebarButton.target = self.revealViewController; 
_sidebarButton.action = @selector(revealToggle:); 

// Set the gesture 
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; 

我無法將動作和目標設置爲普通按鈕。

有沒有簡單的解決方法呢?

感謝

+0

您使用的是iPhone或iPad嗎? –

+0

iPhone的隊友,謝謝。 – user1923975

+0

看看我的答案。 –

回答

1

你可以設置一個UIButton來調用這樣的選擇器:

[button addTarget:self 
      action:@selector(revealToggle:) 
forControlEvents:UIControlEventTouchUpInside]; 
+1

正是我需要的!謝謝 – user1923975

1

爲什麼不你在按鈕的動作把這個代碼:

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Share" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo",@"Choose Existing", nil]; 
[actionSheet showInView:self.view]; 

這種觀點會從屏幕底部上來:

UIActionSheet

+0

@ user1923975這不是一個彈出窗口,但它是一個很好的替代品。 –

+0

它適合你嗎? –

+0

與我想要的風格相比有點不同,但一個很好的方法,要記住這一點。 – user1923975