Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iphone中滚动后,泄露指示器从其位置移动_Iphone_Uitableview_Iphone Sdk 3.2_Cells - Fatal编程技术网

在iphone中滚动后,泄露指示器从其位置移动

在iphone中滚动后,泄露指示器从其位置移动,iphone,uitableview,iphone-sdk-3.2,cells,Iphone,Uitableview,Iphone Sdk 3.2,Cells,我面临一个奇怪的问题。在表视图中,我有3个部分,其中第一部分只有标签和文本字段。第二节和第三节包含表格某些单元格上的文本字段和披露指示符。假设第二节有10个单元格,那么第三节包含披露指示符和其他有文本字段的单元格 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell; NSInteger row

我面临一个奇怪的问题。在表视图中,我有3个部分,其中第一部分只有标签和文本字段。第二节和第三节包含表格某些单元格上的文本字段和披露指示符。假设第二节有10个单元格,那么第三节包含披露指示符和其他有文本字段的单元格

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell;
NSInteger row = [indexPath row];NSLog(@"Row->%d",row);
NSInteger section = [indexPath section];NSLog(@"section->%d",section);
static NSString *CellIdentifier = @"Cell";
static NSString *BillingInfoCellIdentifier = @"BillingCell";
static NSString *DIBillingInfoCellIdentifier = @"DIBillingCell";
static NSString *BCellIdentifier = @"BCell";

switch (indexPath.section) {
    case 0:

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)];
    cellLabel.tag = 56;
    cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [cell.contentView addSubview:cellLabel];
    [cellLabel release];

        switch (indexPath.row) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5: 
                textField = [[UITextField alloc] initWithFrame: CGRectMake(105, 12, 200, 25)];
                textField.clearsOnBeginEditing = NO;
                textField.placeholder  = [[tempArray objectAtIndex:section] objectAtIndex:row];
                [textField setDelegate:self];
                [textField addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
                textField.tag = 57;
                [cell.contentView addSubview:textField];NSLog(@"in adding text fields");
                break;
        }
        break;
    case 1:
        cell = [tableView dequeueReusableCellWithIdentifier:BillingInfoCellIdentifier];
        if (cell == nil) {

            switch (indexPath.row) {
                case 0:
                case 1:
                case 2:
                case 3:
                case 5: 
                case 6:
                case 7:
                case 10:
                case 11:
                    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:BillingInfoCellIdentifier] autorelease];
                    UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)];
                    cellLabel.tag = 56;
                    cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
                    [cell.contentView addSubview:cellLabel];
                    [cellLabel release];
                    cell.accessoryType = UITableViewCellAccessoryNone;
                    textField = [[UITextField alloc] initWithFrame: CGRectMake(105, 12, 200, 25)];
                    textField.clearsOnBeginEditing = NO;
                    textField.placeholder  = [[tempArray objectAtIndex:section] objectAtIndex:row];
                    [textField setDelegate:self];
                    [textField addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
                    textField.tag = 57;
                    [cell.contentView addSubview:textField];NSLog(@"in adding text fields");
                    break;
                case 4:
                case 8:
                case 9:
                    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:BillingInfoCellIdentifier] autorelease];
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)];
                    cellLabel.tag = 56;
                    cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
                    [cell.contentView addSubview:cellLabel];
                    [cellLabel release];
                    break;
            }
            break;

        }
        break;
    case 2:
        cell = [tableView dequeueReusableCellWithIdentifier:BCellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:BCellIdentifier] autorelease];
            UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)];
            cellLabel.tag = 56;
            cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
            [cell.contentView addSubview:cellLabel];
            [cellLabel release];
        }
    break;
}

}
UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:56];
UITextField *TF = (UITextField *)[cell.contentView viewWithTag:57];

switch (indexPath.section) {
    case 0:
        switch (indexPath.row) {
            case 0:
                cellLabel.text = @"First Name:";
                TF. placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 1:
                cellLabel.text = @"Last Name";//TF.text = @"Last Name:";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                NSLog(@"TF.placeholder 1->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]);
                break;
            case 2:
                cellLabel.text = @"eMail";//TF.text = @"email Name:";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                NSLog(@"TF.placeholder 2->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]);
                break;
            case 3:
                cellLabel.text = @"Password";//TF.text = @"pass Name:";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                NSLog(@"TF.placeholder 3->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]);
                break;
            case 4:
                cellLabel.text = @"Confirm";//TF.text = @"conform Name:";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                NSLog(@"TF.placeholder 4->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]);
                break;
            case 5:
                cellLabel.text = @"Phone";//TF.text = @"phone Name:";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                NSLog(@"TF.placeholder 5->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]);
                break;
        }
        break;
    case 1:
        switch(indexPath.row) {
            case 0:
                cellLabel.text = @"First Name";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 1:
                cellLabel.text = @"Last Name";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 2:
                cellLabel.text = @"Phone";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 3:
                cellLabel.text = @"Company";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 5: 
                cellLabel.text = @"Address 1";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 6:
                cellLabel.text = @"Address 2";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 7:
                cellLabel.text = @"City";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 10:
                cellLabel.text = @"Suit";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 11:
                cellLabel.text = @"Zip";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            default:
                cellLabel.text = @"2 else ";
                //TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
        }
        break;
    case 2:
        switch (indexPath.row) {
            case 0:
                cellLabel.text = @"Label 2";
                break;
            case 1:
                cellLabel.text = @"Label 2";
                break;
            default:
                cellLabel.text = @"3.  else Label ";
                break;
        }
        break;
    default:
        break;
}
return cell;
我的问题是,当我上下滚动视图时,比如说3-4次,显示指示器单元格从该位置移动,并放置在该部分的任何位置。若我继续向前滚动,披露指示器将再次置于该位置。如果我删除这些披露指标,只放置文本字段,那么所有这些都会运行良好

我还尝试在CellForRowatinexPath中使用switch case(如下链接中所述),但没有任何帮助…:(

我在谷歌上做了很多,但是没有找到解决这个问题的方法

请在这方面帮助我

问候,,
VM

请查找代码以供参考

第一节包含6个单元格,第二节包含12个单元格,与第三节相同。在第二节和第三节中,第4、8、9号单元格包含披露指示符,其他单元格仅包含文本字段

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell;
NSInteger row = [indexPath row];NSLog(@"Row->%d",row);
NSInteger section = [indexPath section];NSLog(@"section->%d",section);
static NSString *CellIdentifier = @"Cell";
static NSString *BillingInfoCellIdentifier = @"BillingCell";
static NSString *DIBillingInfoCellIdentifier = @"DIBillingCell";
static NSString *BCellIdentifier = @"BCell";

switch (indexPath.section) {
    case 0:

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)];
    cellLabel.tag = 56;
    cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [cell.contentView addSubview:cellLabel];
    [cellLabel release];

        switch (indexPath.row) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5: 
                textField = [[UITextField alloc] initWithFrame: CGRectMake(105, 12, 200, 25)];
                textField.clearsOnBeginEditing = NO;
                textField.placeholder  = [[tempArray objectAtIndex:section] objectAtIndex:row];
                [textField setDelegate:self];
                [textField addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
                textField.tag = 57;
                [cell.contentView addSubview:textField];NSLog(@"in adding text fields");
                break;
        }
        break;
    case 1:
        cell = [tableView dequeueReusableCellWithIdentifier:BillingInfoCellIdentifier];
        if (cell == nil) {

            switch (indexPath.row) {
                case 0:
                case 1:
                case 2:
                case 3:
                case 5: 
                case 6:
                case 7:
                case 10:
                case 11:
                    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:BillingInfoCellIdentifier] autorelease];
                    UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)];
                    cellLabel.tag = 56;
                    cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
                    [cell.contentView addSubview:cellLabel];
                    [cellLabel release];
                    cell.accessoryType = UITableViewCellAccessoryNone;
                    textField = [[UITextField alloc] initWithFrame: CGRectMake(105, 12, 200, 25)];
                    textField.clearsOnBeginEditing = NO;
                    textField.placeholder  = [[tempArray objectAtIndex:section] objectAtIndex:row];
                    [textField setDelegate:self];
                    [textField addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
                    textField.tag = 57;
                    [cell.contentView addSubview:textField];NSLog(@"in adding text fields");
                    break;
                case 4:
                case 8:
                case 9:
                    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:BillingInfoCellIdentifier] autorelease];
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)];
                    cellLabel.tag = 56;
                    cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
                    [cell.contentView addSubview:cellLabel];
                    [cellLabel release];
                    break;
            }
            break;

        }
        break;
    case 2:
        cell = [tableView dequeueReusableCellWithIdentifier:BCellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:BCellIdentifier] autorelease];
            UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)];
            cellLabel.tag = 56;
            cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
            [cell.contentView addSubview:cellLabel];
            [cellLabel release];
        }
    break;
}

}
UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:56];
UITextField *TF = (UITextField *)[cell.contentView viewWithTag:57];

switch (indexPath.section) {
    case 0:
        switch (indexPath.row) {
            case 0:
                cellLabel.text = @"First Name:";
                TF. placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 1:
                cellLabel.text = @"Last Name";//TF.text = @"Last Name:";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                NSLog(@"TF.placeholder 1->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]);
                break;
            case 2:
                cellLabel.text = @"eMail";//TF.text = @"email Name:";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                NSLog(@"TF.placeholder 2->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]);
                break;
            case 3:
                cellLabel.text = @"Password";//TF.text = @"pass Name:";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                NSLog(@"TF.placeholder 3->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]);
                break;
            case 4:
                cellLabel.text = @"Confirm";//TF.text = @"conform Name:";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                NSLog(@"TF.placeholder 4->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]);
                break;
            case 5:
                cellLabel.text = @"Phone";//TF.text = @"phone Name:";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                NSLog(@"TF.placeholder 5->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]);
                break;
        }
        break;
    case 1:
        switch(indexPath.row) {
            case 0:
                cellLabel.text = @"First Name";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 1:
                cellLabel.text = @"Last Name";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 2:
                cellLabel.text = @"Phone";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 3:
                cellLabel.text = @"Company";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 5: 
                cellLabel.text = @"Address 1";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 6:
                cellLabel.text = @"Address 2";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 7:
                cellLabel.text = @"City";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 10:
                cellLabel.text = @"Suit";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            case 11:
                cellLabel.text = @"Zip";
                TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
            default:
                cellLabel.text = @"2 else ";
                //TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row];
                break;
        }
        break;
    case 2:
        switch (indexPath.row) {
            case 0:
                cellLabel.text = @"Label 2";
                break;
            case 1:
                cellLabel.text = @"Label 2";
                break;
            default:
                cellLabel.text = @"3.  else Label ";
                break;
        }
        break;
    default:
        break;
}
return cell;

}

在分配单元格后,尝试执行所有初始化操作,如果之前为零,则不进行条件设置

意思是:

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
 }

现在是单元格初始化的其余部分(它是子视图和更多)

我认为这是您的CellForRowatineXpath中的一个问题。因此,请发布该代码。你好,Rano和观众。您在我发布的代码中发现了任何问题。我仍在努力寻找解决方案…:(很抱歉,最近的评论。Idan是正确的。if块应仅包含初始化,而不包含更多代码。有人在上述代码中发现任何错误吗?我无法修复此问题..:(