开发者

How to pass values between two Custom UITableViewCells in iphone

I have two customized cells in an iphone UITableViewController and would like to capture the data in one cell into another.

I am currently unable to post images and please assume the following points.

  • There are two custom UITableViewcells
  • Notes Textfield in one customcell
  • Submit button in another text开发者_开发问答 field.

Now I want to pass data typed in the notes textfield to be available when I click the Submit button. Is this possible? Please help :(


In general you should store your data separate from views. So if you have some table controller there must data objects like array or dictionary or array of dictionaries. And when you click submit you should get associated data object and work with it.
In your case when textfield lose focus you must get textfield value and store it in your data store.

UPD: It not very clean but can help at first

- (void) textFieldDidEndEditing: (UITextField *) textField {

    // At first need to get cell. findSuperviewWithClass is custom method to find proper superview object
    MyCellClass *cell = (MyCellClass*)[textField findSuperviewWithClass:[MyCellClass class]];

    // and indexPath for it
    NSIndexPath *index = [tableView indexPathForCell:cell];

    // tableData is NSArray of my objects
    MyDataObjClass *dataObj = [tableData objectAtIndex:index.row];

    dataObj.text = textField.text;

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜