0

I have custom UICollectionVIewCell with UILabel and UITextfield as it's property. They both IBOutlet to and connected in Storyboard. This cell get reused in a UICollection view. It get created depending on UILabel count array. So if array has three strings, this cell get created three times. User supposed to enter number in UITextfiled for relevant label. I want to save this number along with label in a dictionary. My problem is I can't get text from UITextfield. Don't know how to do that. I have tried creating instance of UICollectionViewCell and it's textfield property. It's always nil. So app crashes. Please help

OtherPaymentListViewController.h
@interface OtherPaymentListViewController : UIViewController<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@end

//next

@interface OtherPayDeductionCell : UICollectionViewCell
//this is for payment
@property (nonatomic, strong) IBOutlet UILabel *otherPayDeductionTitleLabel;
@property (nonatomic, strong) IBOutlet UITextField *otherPayDeductionAmountTextField;
@end

//data model

@interface OtherPayDeductionsData : NSObject
@property (nonatomic, strong) NSMutableDictionary *otherPaymentsDect;
/*
this dictionary consists of a title from UITextField out side UICollectionViewCell, an array storing UISwitches selected values also  out side UICollectionViewCell, and number string which comes form UITextField in UICollectionViewCell.
*/
@end

//thats where I tried to get textField text

       - (IBAction)unwindToViewController:(UIStoryboardSegue *)segue
        {
        //called by cancel and save buttons in otherPaymentViewController
        NSString *otherPaymentAmountKey = @"other payment key";
        NSString *otherPaymentAmount = @"other payment amount";
        OtherPaymentListViewController *source = [segue sourceViewController];

        //add amount from textbox
        OtherPayDeductionCell *otherPayDeductionCell = [[OtherPayDeductionCell alloc]init];
        otherPaymentAmount = otherPayDeductionCell.otherPayDeductionAmountTextField.text;
        //otherPaymentAmount always nil. Although textfield has some numbers in it.

        [source.otherpaymentDict setObject:otherPaymentAmount forKey:otherPaymentAmountKey];
        NSLog(@"Dictionary %@", source.otherpaymentDict);

        }
fguchelaar
  • 4,779
  • 23
  • 36
user2511630
  • 3,214
  • 2
  • 17
  • 15
  • Can you please add the code you use as your datasource for the collection view and the part where the user is trying to interact with the cell to your question? – Cornelius Jun 19 '14 at 18:20
  • you can set tag or you can set delegate of UITextField named textFieldShouldReturn and take a string of textField .... – Mubin Mall Jun 19 '14 at 19:32

0 Answers0