-1

私はtextfieldとを持っていtableviewます。ユーザーは、またはその他のtextfieldデータからデータを選択できます。しかし、ユーザー自身のデータを入力した後、私は消える必要があります。これを達成するにはどうすればよいですか。tableviewtableviewdid select rowtableview

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

        UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
        txtcity.text = selectedCell.textLabel.text;


      }
     -(void)hideKeyboard  //this is my gesture recogniser method
      {

         autocompletetableview.hidden=true;//if i didn't use this statement it enter into didselectrow method
      }
     - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {


   autocompleteTableView.hidden=YES;
    if( textField == txtcity)
   {


    autocompleteTableView.hidden = NO;

     NSString *substring = [NSString stringWithString:textField.text];
         substring = [substring stringByReplacingCharactersInRange:range withString:string];
     [self searchAutocompleteEntriesWithSubstring:substring];// this method loads data    into my tableview



      return YES;
     }


   }

   (BOOL)textFieldShouldEndEditing:(UITextField *)textField
   {
    if([txtcity.text isEqualToString:@""])
    {
    autocompleteTableView.hidden=YES;

    return YES;
     }
    else
    autocompleteTableView.hidden=NO;
   }

  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) section {


   return arr2.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 = [[arr2 objectAtIndex:indexPath.row]objectForKey:@"Name"];
    cell.textLabel.font=[UIFont boldSystemFontOfSize:12];
     cell.textLabel.numberOfLines=0;

   return cell;
}

このように使用すると、行を選択すると、インデックスパスメソッドで行を選択しません。助けて

私はresignfirstresponderを使用しなければならない場所に行きません

4

2 に答える 2

1

resignFirstResponderファーストレスポンダ ( の場合はキーボードUITextField) を閉じるために使用されます。テーブルビューを非表示にする場合は、プロパティを true に設定するhiddenか、ビュー階層からテーブルビューを削除します。

すなわち;

[tableView setHidden:YES]

また

[tableView removeFromSuperview];

更新: 親ビューのタップをチェックするためにジェスチャ レコグナイザーを使用する場合、ジェスチャ メソッドが不必要に起動されないように、次の操作を実行できます。

このすべてのコードをビュー コントローラーで全体的に記述していると想定しています。

UITapGestureRecognizer *tapGe = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
tapGe.numberOfTapsRequired = 1;
tapGe.delegate =self;
[self.view addGestureRecognizer:tapGe]

次に、View Controller に次のメソッドを実装します (UIGestureRecognizerDelegateプロトコルに準拠させる)。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
  If(touch.view==self.view){
     return YES; //If its the main view accept the touch
  }else{
     return NO; //Otherwise(say tableview) don't consume the touch.
  }
}
于 2013-03-14T14:36:20.613 に答える
0

私はカスタムセルを使用しており、ここに作業コードを示しています。

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [mainDetaileArray count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 115;
}


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



    static NSString *CellIdentifier = @"Cell";

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"ProductMerchantCell" owner:nil options:nil];

        for (UIView *view in views)
        {
            if([view isKindOfClass:[UITableViewCell class]])
            {
                cell = (ProductMerchantCell*)view;
                //cell.img=@"date.png";

            }
        }
    }

    cell.selectionStyle=UITableViewCellSelectionStyleNone;



        txtfield = [[UITextField alloc]initWithFrame:CGRectMake(104, 36, 58, 31)];
        txtfield.textColor = [UIColor colorWithRed:56.0f/255.0f green:84.0f/255.0f blue:135.0f/255.0f alpha:1.0f];
        txtfield.delegate = self;
        txtfield.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        txtfield.returnKeyType = UIReturnKeyDone;
        indexVal = indexPath.row;

        [txtfield setBorderStyle:UITextBorderStyleRoundedRect];
        txtfield.textAlignment = UITextAlignmentCenter;
        txtfield.text = [quantity_array objectAtIndex:indexPath.row];
   // NSLog(@" txtfield.text %@", txtfield.text);
        [txtfield setTag:indexPath.row];

        [txtfield setAutocapitalizationType:UITextAutocapitalizationTypeWords];


        NSString *total_str_price1=[[mainDetaileArray objectAtIndex:indexPath.row]valueForKey:@"total_product_price"];

        cell.availbl_pro_lbl.text=[NSString stringWithFormat:@"Total : %@%@",add_currnce_str,total_str_price1];

        cell.title_pro_lbl.text=[[mainDetaileArray objectAtIndex:indexPath.row]valueForKey:@"product_title"];

        str_price=[[mainDetaileArray objectAtIndex:indexPath.row]valueForKey:@"product_price"];

        cell.price_Pro_lbl.text=[NSString stringWithFormat:@"Price : %@%@",add_currnce_str,str_price];

        [cell.contentView addSubview:txtfield];


    return cell;

   }
- (void)textFieldDidEndEditing:(UITextField *)textField
{

    addtoValue = textField.text;
    [quantity_array replaceObjectAtIndex:textField.tag withObject:textField.text];


   // NSLog(@"quantity_array %@",quantity_array);
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {

    [textField resignFirstResponder];
    [cell.Quantity_txt resignFirstResponder];
    return YES;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [cell.Quantity_txt resignFirstResponder];
}
于 2013-03-14T15:03:43.987 に答える