2013-02-28 9 views
1

我遇到了一個大問題。我有一個textfield其中我正在做自動完成功能來顯示內部tappe時的項目列表。我在tableView(自動完成tableView)中顯示項目。我有一個UIbutton低於textfield。現在,當我從自動完成文本字段中選擇一個項目並單擊該按鈕時,它沒有響應。 我不知道爲什麼。將UIButton帶到滾動視圖的前面

我在didendediting把它前面,也didSelectrow但沒有use.I的添加了一個UIbuttonScrollView(testScroll)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
      Name.text = selectedCell.textLabel.text; 
      [Name resignFirstResponder]; 
      [testScroll bringSubviewToFront:btnSearch]; 
      autocompleteTableView.hidden=true; 
} 
-(void)textFieldDidEndEditing:(UITextField *)textField{ 
if(textField==CompanyName) 
    { 

     [testScroll bringSubviewToFront:btnSearch]; 

} 

}

我在哪裏要去錯了嗎?

編輯:

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



    if(textField==Name) 
    { 

     autocompleteTableView.hidden = NO; 

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

     } 
    } 



} 


- (void)connectionDidFinishLoading:(NSURLConnection *)connection 

{ 

     parser = [[NSXMLParser alloc] initWithData:receivedData]; 
     [parser setDelegate:self]; 
     [parser setShouldProcessNamespaces:NO]; 
     [parser setShouldReportNamespacePrefixes:NO]; 
     [parser setShouldResolveExternalEntities:NO]; 
     [parser parse]; 
     [parser release]; 



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



      if(autocompleteTableView) 
       [autocompleteTableView removeFromSuperview]; 

      autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,295,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(220,370 ,295,autocompleteTableView.frame.size.height)]; 


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

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

       [autocompleteUrls addObject:curString]; 

      } 




     } 
     [autocompleteTableView reloadData]; 


} 
+0

Whay您使用滾動使用表格視圖...任何方式更改的所有意見,綠紅藍什麼,然後運行你的應用程序的顏色U將得到公平的想法 – amar 2013-02-28 05:37:05

+0

嗨@arizah,粘貼自動完成的tableview代碼。可能在文本字段中顯示選定的值後,tableview不會完全消失並隱藏其下面的按鈕。請檢查。 – 2013-02-28 05:37:38

+0

chck if button id touchable – rptwsthi 2013-02-28 05:39:35

回答

2

我經歷了同樣的問題和固定的下面的代碼的幫助。

編輯下面如下兩個功能:

in .h: 

int isValueSelected; 

在的.m:

在viewDidLoad中: isValueSelected = 0;

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

     if (isValueSelected == 1) 
     { 
      autocompleteTableView.hidden = YES; 
      isValueSelected = 0; 
     }else{ 
      NSString *substring = [NSString stringWithString:textField.text]; 
      substring = [substring stringByReplacingCharactersInRange:range withString:string]; 
      [self searchAutocompleteEntriesWithSubstring:substring]; 
      if((substring.length ==0) || ([substring characterAtIndex:0] == 10) || (autocompleteUrls.count == 0)){ 
       autocompleteTableView.hidden = YES; 
      }else{ 
       autocompleteTableView.hidden = NO; 
      } 


     } 

     return YES; 
    } 


    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

     UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; 
     urlField.text = selectedCell.textLabel.text; 
     isValueSelected = 1; 
     autocompleteTableView.hidden = YES; 

    } 
+0

是的,我剛剛嘗試,仍然沒有得到按鈕clickable.I不知道y?我的didfinishloading代碼是否正確?請找到解決方案 – Honey 2013-02-28 07:08:37

+0

我可以知道這是什麼([substring characterAtIndex:0] == 10)? – Honey 2013-02-28 07:16:46

+0

嘿你有沒有檢查? – Honey 2013-02-28 11:43:09