簡體   English   中英

UITextField在UITableView中委托

[英]UITextField Delegate in UITableView

G'day伙計們,我正在構建一個允許用戶快速將數字輸入UITableView的應用程序。

我目前已經構建了這個框架,但是我有點想法讓鍵盤加載並使單元格中的文本可以通過用戶操作進行編輯。

我記得在某個地方的開發代碼中有一個iOS示例(就像一年前那樣它不會在NDA下),你在UITableView的上下文中添加了項目並對其進行了編輯,而沒有進入詳細的子視圖。

只需要提示如何連接代理,或者如何構造代碼。

我有代碼,我為UITableView創建自定義單元格,它們上面有UITextFieldUITextView控件。 UITableViewController代碼中我這樣做:

接口

@interface MyTableViewController: 
    UITableViewController <UITextFieldDelegate, UITextViewDelegate> {
....
}

履行

-(UITableViewCell *) tableView:(UItableView *) tableView 
    cellForRowAtIndexPath: (NSIndexPath *) indexPath {

    ....

    UITableViewCell * cell = ....
    cell.myTextField.delegate = self;
    cell.myTextField.tag = 1; //This should be unique.
    return cell;
}

-(void) textFieldDidEndEditing: (UITextField * ) textField {
    // Decide which text field based on it's tag and save data to the model.
}

-(void) textViewDidEndEditing: (UITextView * ) textView {
    // Decide which text view based on it's tag and save data to the model.
}

您可以將UITextField或UITextView添加到任何單元格。 如果您有自定義單元格,請將它們作為文本視圖的委托,或者如果您在表格視圖委托中組成單元格,則將其設為文本字段的委托。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM