隐藏后的CustomView(UITableView)必须访问Customview区域下的UITextFields

时间:2013-02-22 07:11:02

标签: iphone uitableview xcode4.5

我在UITableView开始编辑时收到UITextField我的功能完成后隐藏了这个内容。

我采取了静态UITableView。我的问题是在隐藏UITableView(CustomView)后我无法访问UITextFields以下(UITableView区域中存在)

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
        if(textField==CompanyName)
        {
            autocompleteTableView.hidden = NO;
                NSString *substring = [NSString stringWithString:textField.text];
                substring = [substring stringByReplacingCharactersInRange:range withString:string];
                [self searchAutocompleteEntriesWithSubstring:substring];
                return YES;
                if([CompanyName.text length]==0)
                {
                    autocompleteTableView.hidden = YES;

                }
        }


        if([arr4 count]!=0)
        {
            self.autocompleteUrls = [[[NSMutableArray alloc] init]autorelease];
            viewForautoCompleteTableView = [[UIView alloc]initWithFrame:CGRectMake(10, 110, 195, 230)];

            if(autocompleteTableView)
                [autocompleteTableView removeFromSuperview];

            autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,195,150) style:UITableViewStyleGrouped];
            autocompleteTableView.delegate = self;
            autocompleteTableView.dataSource = self;
            autocompleteTableView.scrollEnabled = YES;
            autocompleteTableView.backgroundColor = [UIColor lightTextColor];
            autocompleteTableView.rowHeight=28;

            autocompleteTableView.backgroundView = nil;
            autocompleteTableView.backgroundColor = [UIColor whiteColor];


            autocompleteTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            [autocompleteTableView setSeparatorColor:[UIColor orangeColor]];
            [viewForautoCompleteTableView setFrame:CGRectMake(10,110 ,195,autocompleteTableView.frame.size.height)];


            [viewForautoCompleteTableView addSubview:autocompleteTableView];
            [self.view addSubview:viewForautoCompleteTableView];

            [autocompleteUrls removeAllObjects];
            for(int i=0;i<[arr4 count];i++)
            {
                NSString *curString = [[arr4 objectAtIndex:i] valueForKey:@"Name"];
                [autocompleteUrls addObject:curString];

            }
        }
    [autocompleteTableView reloadData];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(currentHtmlElement==@"5")
    {
        UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
        CompanyName.text = selectedCell.textLabel.text;
        autocompleteTableView.hidden=YES;
    }
}

1 个答案:

答案 0 :(得分:0)

添加textField委托如下: 它可以帮到你..

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [self.view bringSubviewToFront:btnuserLocation];
    autocompleteTableView.hidden=true;
}

和按钮更改控制UI按钮的事件从UIControlEventTouchDown到UIControlEventTouchUpInside,如下所示:

[btnuserLocation addTarget:self
                    action:@selector(showLocation:)
                forControlEvents:UIControlEventTouchUpInside];

只要从textField中删除焦点,它就会隐藏你的表视图。让你点击tableView后面的按钮。