Iphone 带UISwitch的UITableViewCell会导致.tag=1变为空

Iphone 带UISwitch的UITableViewCell会导致.tag=1变为空,iphone,xcode,ios4,Iphone,Xcode,Ios4,我有一个6行的自定义tableview。5行中有UITextFields,1行中有UISwitch 我添加如下文本框: switch (indexPath.row) { case 0: txtLabel.text = NSLocalizedString(@"Name:", @""); txtField.tag=1; [txtField becomeFirstResponder]

我有一个6行的自定义tableview。5行中有UITextFields,1行中有UISwitch

我添加如下文本框:

switch (indexPath.row) {
            case 0:
                txtLabel.text = NSLocalizedString(@"Name:", @"");
                txtField.tag=1;
                [txtField becomeFirstResponder];
                [cell.contentView addSubview:txtField];
                [txtField release];
                break;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
添加的开关如下所示:

case 3:
                txtLabel.text = NSLocalizedString(@"Male:", @"");
                UISwitch *mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
                cell.accessoryView = mySwitch;
                [mySwitch setTag:6];
                break;
我用另一种方法读取值,如:

UITextField *daName = (UITextField *)[self.view viewWithTag:1];
但出于某种原因,只要我添加UISwitch,daName值就会变为null。其他值读取良好(因此标记2正常,标记3正常等)

我错过了什么?因为当我移除UISwitch时,我从标记1得到一个值

提前谢谢

编辑


我只是看到,只要我在tableview中有6行,标记id为1的元素就会变为null。。。只要我有5行,我就可以得到所有的值…

我在stackoverflow的某个地方读到,当你设置标签时,你不应该使用0或1,我不记得在哪里,但我想它提到了一些关于默认值的东西?可能值得搜索…

好的,我添加了一个可变数组,并将文本字段添加到数组中。这样我就不必再使用标签了,而且工作正常……

一次显示多少行,甚至部分显示?表现在有6行,5行带有标签和UITextView,1行带有标签和UISwitch。他们一次展示了所有这些,我也尝试过,也使用标签id从100开始,但结果相同。。谢谢你的回复!您不应该使用0,因为0是所有视图的默认标记。ie每个没有显式设置标记的视图都有一个标记0。
 UISwitch *daName = (UISwitch *)[self.view viewWithTag:tag];

 if (daName.on){
  // handle the switch of particular of tag 


}