I have a custom tableview with 6 rows. 5 rows have UITextFields in them, and 1 row has a UISwitch in it.
I add the textboxes like this:
switch (indexPath.row) {
case 0:
txtLabel.text = NSLocalizedString(@"Name:", @"");
txtField.tag=1;
[txtField becomeFirstResponder];
[cell.contentView addSubview:txtField];
[txtField release];
break;
in the
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
The switch is added like:
case 3:
txtLabel.text = NSLocalizedString(@"Male:", @"");
UISwitch *mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
cell.accessoryView = mySwitch;
[mySwitch setTag:6];
break;
I read the values in another method like:
UITextField *daName = (UITextField *)[self.view viewWithTag:1];
But for some reason, as soon as I add the UISwitch, the daName value becomes null. The other values are read well (so tag 2 is ok, tag 3 is ok etc.)
What am I missing here? Because when I remove the UISwitch then I get a value back from tag 1…
Thanks in advance!
EDIT
I just see that as soon as I have 6 rows in my tableview the element with tag id 1 gets null… As soon as I have 5 rows, I can get all values…
Ok I’ve added a mutablearray and added the textfields into the array. That way I don’t have to use the tag anymore and that is working fine…