0

私は問題があります。

UITableViewCellのサブビューであるボタンをクリックした後にパラメータを渡そうとしています。ソースコードは次のとおりです。

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

    MSContactCell *cell = (MSContactCell *)[_tableView dequeueReusableCellWithIdentifier: cellWithCheckId];
    MSContact *contact = [self.list objectAtIndex:indexPath.row];

    if (cell == nil)
        {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"MSContactCell"
                                                  owner:self
                                                options:nil] lastObject];

          cell.delegate = self;
        // cell.index = indexPath.row;

            cell.backgroundView.backgroundColor = [UIColor colorWithRed:0.882 green:0.863 blue:0.839 alpha:1.0];
        }
    cell.title.text = [contact contactName];
    cell.jobTitle.text = [contact jobDescription];

    cell.callButton.contactStr = [contact phoneNumber];
      [cell.callButton addTarget:self action:@selector(callPressed:) forControlEvents:UIControlEventTouchUpInside];         
    return cell;
}

と:

- (IBAction)callPressed:(id)sender
{
        contactButton *button = (contactButton *)sender;

    UIDevice *device = [UIDevice currentDevice];
    if ([[device model] isEqualToString:@"iPhone"] ) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", button.contactStr]]];
    } else {
        UIAlertView *Notpermitted=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [Notpermitted show];
        [Notpermitted release];
    }
 }

すべて問題ないようですが、デバッグ時に問題が発生します。

 (lldb) po button
   $4 = 0x2084d5a0 <MSContactCell: 0x2084d5a0; baseClass = UITableViewCell; frame = (0 0; 320 95);        
   autoresize = W; layer = <CALayer: 0x2085dd70>>

ボタンをセルではなくボタンとして認識するにはどうすればよいですか?

ありがとう!

4

3 に答える 3

1

送信者がMSContactCell理由である場合は、それを使用してcontactButton

 - (IBAction)callPressed:(id)sender
  {
    contactButton *myCell = (MSContactCell *)sender;
    contactButton *button = myCell. callButton;
    ...

  }
于 2013-03-19T10:15:19.390 に答える
1

どの行にこれを与えます...

      (lldb) po button
      $4 = 0x2084d5a0 <MSContactCell: 0x2084d5a0; baseClass = UITableViewCell; frame  = (0 0; 320 95);        
    autoresize = W; layer = <CALayer: 0x2085dd70>>

cellForRowAtIndexPathメソッドでは、buttonのタグ値もindexpath行として設定する必要があると思います。

    cell.callButton.tag=[indexPath row]

そのため、各ボタンを簡単に認識できます。

それでも、ボタンをカスタムビューとしてテーブルビューセルに追加すると、より簡単になります。

于 2013-03-19T10:28:15.143 に答える
1

内部でこれを試してください

   - (IBAction)callPressed:(id)sender
{
    for (UIView *parent = [sender superview]; parent != nil; parent = [parent superview]) {
            if ([parent isKindOfClass: [UITableViewCell class]]) {
                UITableViewCell *cell = (UITableViewCell *) parent;
                UIButton * button =  (UIButton *)[cell viewWithTag:yourButtonsTag];
               }
    }
}
于 2013-03-19T11:49:21.860 に答える