2012-03-06 82 views
2

我已經創造了一種在用戶輸入一個電話number.How的EntryElement我可以在元素的末尾添加一個按鈕,以便用戶可以按下按鈕並撥打電話?添加按鈕EntryElement

+0

爲什麼不作出回答而不是評論?這正是要做的事情! – Krumelur 2012-03-06 18:36:43

回答

0

您需要創建一個新的元素是EntryElement的子類,重寫獲得Cell方法,並添加到accessoryView的按鈕。

+1

我不知道如何在對話完成後回到應用程序,然後看看這個。 http://stackoverflow.com/questions/9264065/is-it-possible-to-go-back-automatically-into-the-application-after-calling-a-num – MemoDreamer 2012-03-07 08:25:35

+0

小區的物業accessoryView的是空。相反,我將該按鈕添加到單元格的子視圖中,作爲_cell.Subviews [0] .AddSubview(btn)'。這是一樣的嗎? – 2012-03-13 10:19:25

0

我知道這並不完全回答這個問題,但我奮鬥了很長一段時間,直到我發現@Janub的答案,讓我在正確的軌道上。這是我目前正在工作的代碼。

public class NextNumericCell : EntryElement 
{ 
    readonly EventHandler handler; 
    public NextNumericCell (string caption, string placeholder, string value, EventHandler onClick) : base(caption,placeholder,value) 
    { 
     handler = onClick; 
    } 

    protected override UITextField CreateTextField (CGRect frame) 
    { 
     var textField = base.CreateTextField (frame); 
     var toolBar = new UIToolbar (new CGRect (0, 0, frame.Width, 35)); 
     var spacerButton = new UIBarButtonItem (UIBarButtonSystemItem.FlexibleSpace); 
     var buttonTitle = ReturnKeyType == null ? "SetButtonTitle" : ReturnKeyType.ToString(); 
     var nextButton = new UIBarButtonItem (buttonTitle, UIBarButtonItemStyle.Plain, handler); 
     toolBar.Items = new UIBarButtonItem [] { spacerButton, nextButton }; 
     textField.InputAccessoryView = toolBar; 
     return textField; 
    } 
}