开发者

How to get values from custom cells with textfield UITableView?

I have created a UITableView which function like this section 0 2 custom cells (First name,last name with UITextFields) section 1 (tap a button on header insert a new cell with textfield + a Button to change the title) section 2 (tap a button on header insert a new cell with textfield + a Button to change the title) section 3 (tap a button on header insert a new cell with textfield + a Button to change the title ). Now suppose I create a 3-3 rows in each section except section 0. How do i dynamically get all the tex开发者_Python百科tfields values?


You have a datasource for your TableView. This source should be updated automatically everytime you insert a new cell. So if you iterate through the array containing your datasource there should also be the values of the textfield somewhere.

If this isn't the case you should think about the way you are adding the new cells. Usually in your datasource there should be reserved some space for the data in the textfield. If you create a new Cell now, the space reserved for the data of the textfield should be updated with the new data.

If I understand you correctly you have a cell with a lable and a textfield and a button. you create a cell, enter some text in the textfield and then press the button. then the content of the textfield should be displayed in the label.

If i'm wrong please shove me in the right direction. Maybe you can post some screenshots or something.

!!!!! Wrong approach !!!!!!!

Iterate through your cells you get from the method

[tableView visibleCells];

and then get the value from the textField contained in the cell via

NSArray *myArray = [[NSArray alloc] initWithArray: [tableView

visibleCells]]; [[(YourCellSubClass*)myArray textfield] text];

I have not tested this, but i think it should work.

!!!!!! Wrong approach end !!!!!!


you must set delegate of UITextField the ViewController in which you have the UITableView. then override this method to get the text of focused textfield textField:DidEndEditing. Also you can set the tags for each UITextfield to differentiate them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜