Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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 TableView未隐藏在xcode中的DidSelectRowatineXpath中?_Iphone_Xcode_Uitableview_Autocomplete - Fatal编程技术网

Iphone TableView未隐藏在xcode中的DidSelectRowatineXpath中?

Iphone TableView未隐藏在xcode中的DidSelectRowatineXpath中?,iphone,xcode,uitableview,autocomplete,Iphone,Xcode,Uitableview,Autocomplete,我对objective-C相当陌生,并为UItextField实现了自动完成功能的概念。我可以适当地做到这一点。但当我选择一个特定单元格时,该单元格的文本应该显示在UItextField中,相应的tableView必须隐藏。但我无法在选择单元格后隐藏UITableView。我要去哪里错了吗 - (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring { NSURL *urlString= [NSString

我对objective-C相当陌生,并为UItextField实现了自动完成功能的概念。我可以适当地做到这一点。但当我选择一个特定单元格时,该单元格的文本应该显示在UItextField中,相应的tableView必须隐藏。但我无法在选择单元格后隐藏UITableView。我要去哪里错了吗

- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {


    NSURL *urlString= [NSString stringWithFormat:@"http://179.87.89.90/services/Service.svc/GetCities/?p=%@&k=%@",substring,txtId.text];     
    NSURL *jsonUrl =[NSURL URLWithString:urlString];
    NSString *jsonStr = [[NSString alloc] initWithContentsOfURL:jsonUrl];  
    parser = [[NSXMLParser alloc] initWithContentsOfURL:jsonUrl];
    currentHTMLElement=@"3";
    [parser setDelegate:self];
    [parser setShouldProcessNamespaces:NO];
    [parser setShouldReportNamespacePrefixes:NO];
    [parser setShouldResolveExternalEntities:NO];
    [parser parse];
    [parser release];
    NSLog(@"%@",arr2);



    if([arr2 count]!=0)
    {
        self.autocompleteUrls = [[NSMutableArray alloc] init];

        autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(88, 447, 200, 120) style:UITableViewStyleGrouped];
        autocompleteTableView.delegate = self;
        autocompleteTableView.dataSource = self;
        autocompleteTableView.scrollEnabled = YES;
        // autocompleteTableView.hidden = YES;  
        [self.view addSubview:autocompleteTableView];
        [autocompleteUrls removeAllObjects];
            for(int i=0;i<[arr2 count];i++)
            {
                NSString *curString = [[arr2 objectAtIndex:i] valueForKey:@"Name"];

                NSRange substringRange = [curString rangeOfString:substring];

                if (substringRange.location == 0) 
                    [autocompleteUrls addObject:curString];  

            }
      [autocompleteTableView reloadData];
    }
    else
    {
        autocompleteTableView.delegate=nil;
        autocompleteTableView.dataSource=nil;
        autocompleteTableView.hidden = YES;  

    }

}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {



    if( textField == txtcity)
    {
     autocompleteTableView.hidden = NO;
    NSString *substring = [NSString stringWithString:textField.text];
    substring = [substring stringByReplacingCharactersInRange:range withString:string];
    [self searchAutocompleteEntriesWithSubstring:substring];
    return YES;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) section {
    return autocompleteUrls.count;
}

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

    UITableViewCell *cell = nil;
    static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";
    cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] 
                 initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier] autorelease];
    }

    cell.textLabel.text = [autocompleteUrls objectAtIndex:indexPath.row];
    cell.textLabel.font=[UIFont boldSystemFontOfSize:12];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    txtcity.text = selectedCell.textLabel.text;
    [autocompleteUrls removeAllObjects];
    [self.autocompleteTableView setHidden:YES];    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

        UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
        txtcity.text = selectedCell.textLabel.text;
        [autocompleteUrls removeAllObjects];
        autocompleteTableView.hidden=YES;

    }
-(void)searchAutoCompleteTentriesWithSubString:(NSString*)子字符串{
NSURL*urlString=[NSString stringWithFormat:@]http://179.87.89.90/services/Service.svc/GetCities/?p=%@&k=%@”,子字符串,txtId.text];
NSURL*jsonUrl=[NSURL URLWithString:urlString];
NSString*jsonStr=[[NSString alloc]initWithContentsOfURL:jsonUrl];
parser=[[NSXMLParser alloc]initWithContentsOfURL:jsonUrl];
CurrentHtmleElement=@“3”;
[解析器setDelegate:self];
[解析器setShouldProcessNamespaces:否];
[解析器setShouldReportNamespacePrefixes:否];
[解析器setShouldResolveExternalEntities:否];
[语法分析器解析];
[解析器发布];
NSLog(@“%@”,arr2);
如果([arr2计数]!=0)
{
self.autocompleteUrls=[[NSMutableArray alloc]init];
autocompleteTableView=[[UITableView alloc]initWithFrame:CGRectMake(88447200120)样式:UITableViewStyleGroup];
autocompleteTableView.delegate=self;
autocompleteTableView.dataSource=self;
autocompleteTableView.scrollEnabled=是;
//autocompleteTableView.hidden=是;
[self.view addSubview:autocompleteTableView];
[自动完成删除所有对象];
对于(int i=0;i您是否尝试过:

[self.tableView setHidden:YES];

问题在于if条件,当
if
的计算结果为真时,
autocompleteTableView
将再次分配并添加到self.view。它将放置在上一个tableView上,您将丢失上一个tableView的引用。如果调用
autocompleteTableView.hidden=YES
。上次添加de>tableView
将被隐藏。但以前添加的tableView将在那里

只需更改if块,如下所示:

if([arr2 count]!=0)
{
    self.autocompleteUrls = [[NSMutableArray alloc] init];
    if(autocompleteTableView)
         [autocompleteTableView removeFromSuperView];
    autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(88, 447, 200, 120) style:UITableViewStyleGrouped];
    autocompleteTableView.delegate = self;
    autocompleteTableView.dataSource = self;
    autocompleteTableView.scrollEnabled = YES;
    // autocompleteTableView.hidden = YES;  
    [self.view addSubview:autocompleteTableView];
        for(int i=0;i<[arr2 count];i++)
        {
            NSString *curString = [[arr2 objectAtIndex:i] valueForKey:@"Name"];

            NSRange substringRange = [curString rangeOfString:substring];

            if (substringRange.location == 0) 
                [autocompleteUrls addObject:curString];  

        }
  [autocompleteTableView reloadData];
}
if([arr2计数]!=0)
{
self.autocompleteUrls=[[NSMutableArray alloc]init];
if(自动完成表格视图)
[autocompleteTableView从SuperView移除];
autocompleteTableView=[[UITableView alloc]initWithFrame:CGRectMake(88447200120)样式:UITableViewStyleGroup];
autocompleteTableView.delegate=self;
autocompleteTableView.dataSource=self;
autocompleteTableView.scrollEnabled=是;
//autocompleteTableView.hidden=是;
[self.view addSubview:autocompleteTableView];

对于(int i=0;i@Arizah-请尝试制作一个新的应用程序来测试UItableview和UItextField委托方法。可能是在某个地方--

由于没有委托方法而被调用,如:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
将不会被调用。请尝试避免使用此代码

还有语句:
self.autocompleteUrls=[[NSMutableArray alloc]init];
技术上不正确,因为保留属性不需要分配。您可以使用:

NSMutableArray *theArray= [[NSMutableArray alloc] init];
self.autocompleteUrls = theArray;
[theArray release];

尽管如此,
autocompleteTableView.hidden=YES;
试试
tableView.hidden=YES;
还是不行我想你在其他地方遇到了问题….
autocompleteTableView.hidden=YES;
tableView.hidden=YES;
正在很好地编辑我的代码你能看看并纠正我的错误吗t是我从中检索到的数组响应url@simone听到两个和你的答案一样的答案,你的大脑中是否没有新的密码answer@nitintableView与self.tableView不同。如果您有属性,但现在当我选择单元格时,tableView将消失,但选定的单元格文本不会显示在UITextField中。-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath{没有被调用…我应该修改什么elz?@arizah:
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath
正在工作,否则它不会隐藏tableView。k得到了..非常感谢。我为此绞尽脑汁..再次感谢你
NSMutableArray *theArray= [[NSMutableArray alloc] init];
self.autocompleteUrls = theArray;
[theArray release];