Thursday, 5 September 2013

Need to enable a UIButton only when multiple UITextFields are filled in iOS

Need to enable a UIButton only when multiple UITextFields are filled in iOS

I am working on an iOS application where I have a UITableView that
contains custom UITableViewCell's. Each cell in the table contains a
UITextField that receives numeric input. Underneath the UITableView is
another view that contains buttons, and one of these buttons needs to be
disabled until all of the UITextFields in the UITableView have been
filled. Once all of the UITextFields are full, then and only then does the
button become enabled. How do I do this? I have the following relevant
code:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
static NSString *cellIdentifier = @"Cell";
_cell = (SimpleTableCell *)[tableView
dequeueReusableCellWithIdentifier:cellIdentifier];
if (_cell == nil) {
_cell = [[SimpleTableCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier];
}
_cell.dataField.tag = indexPath.row;
_cell.dataField.delegate = self;
_cell.dataField.contentVerticalAlignment =
UIControlContentVerticalAlignmentCenter;
[_cell.dataField setTextAlignment:NSTextAlignmentRight];
[_cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return _cell;
}
I am implementing the UITextFieldDelegate and I figure my solution will
have to work with the method:
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
}
However, I'm not sure how to enable a particular button ONLY when all
UITextFields in the table have data in them. Can anyone show me how to do
this?
Thanks in advance to all who reply.

No comments:

Post a Comment