菜鸟教程小白 发表于 2022-12-11 19:21:15

ios - 在 didSelectRowAtIndexPath 执行后 UITableViewCells 消失了吗?


                                            <p><p>我有两个 TableView ,在第一个 <code>UITableView</code>(联系人 TableView )中加载了所有单元格,当我触摸一个单元格时,它会转到详细联系人,一切都很好。
在第二个 <code>UITableView</code> (详细联系人)中,当我触摸单元格(调用联系人)和第二个 <code>UITableView</code> 方法 <code>didSelectRowAtIndexPath</code> 执行时,它可以工作但会导致所有数据(联系人)在第一个 <code>UITableView</code> 中消失。我该如何解决?</p>

<hr/>

<p>附:</p>

<p>(如果我在第二个 <code>UITableView</code> 中禁用 <code>didSelectRowAtIndexPath</code>,数据将保留在第一个 TableView 中)
(表格 View 之间没有segue)</p>

<hr/>

<p>第一个<code>UITableView</code>:</p>

<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *kCellId = @&#34;UIContactCell&#34;;

    UIContactCell *cell = ;
    //cell.imageLabel.alpha=0;
    cell.imageView.image=nil;
    if (cell == nil) {
      cell = [[ initWithIdentifier:kCellId] autorelease];
      cell.imageView.image=nil;

      // Background View
      //      UACellBackgroundView *selectedBackgroundView = [[ initWithFrame:CGRectZero] autorelease];
      //      cell.selectedBackgroundView = selectedBackgroundView;
      //      ;
    }
    OrderedDictionary *subDic = addressBookMap[];

    NSString *key = subDic.allKeys;
    ABRecordRef contact = subDic;
    CFDataRef imageData = ABPersonCopyImageData(contact);
    UIImage *image = nil;

    image = ;


    // Cached avatar
    id data = avatarMap[@(ABRecordGetRecordID(contact))];
    if(data == nil) {
      //CFRelease(imageData);
      //image = ;
      if(image != nil) {
            avatarMap[@(ABRecordGetRecordID(contact))] = image;
      } else {
            avatarMap[@(ABRecordGetRecordID(contact))] = ;
      }
    }
    else if(data != ) {
      image = data;
    }
    NSString *name=(NSString *)ABRecordCopyValue(contact, kABPersonFirstNameProperty);
    NSString *family=(NSString *)ABRecordCopyValue(contact, kABPersonLastNameProperty);

    if(image == nil) {
      //image = ;
      RandomColor *random=[ init];
      cell.avatarImage.backgroundColor=];

      cell.imageView.image=nil;
      // cell.imageView.backgroundColor=;

      cell.imageLabel.alpha=1;

    }
    //      CFDataRef imageData1 = ABPersonCopyImageData(contact);
    //      UIImage *image1 = nil;
    //
    //      image1 = ;

    else{
      cell.imageLabel.alpha=0;}
    cell.imageView.image=nil;
    cell.avatarImage.image = image;


    cell.contact = contact;
    cell.imageView.image=nil;
    return cell;
}


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

    UIStoryboard *storyboard = ;
    ContactProfileViewController *nextview = ;
    OrderedDictionary *subDic = addressBookMap[];
    ABRecordRef lPerson = subDic[];
    // ContactProfileViewController *nextview=[ init];
    nextview.person=lPerson;
    [self presentViewController:nextview animated:YES completion:^{

    }];
}
</code></pre>

<p>第二个<code>UITableView</code>:</p>

<pre><code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AddContactTableViewCell *cell=;
    CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(self.phoneNumbers, indexPath.row);
    CFStringRef locLabel = ABMultiValueCopyLabelAtIndex(self.phoneNumbers, indexPath.row);

    NSString *phoneNumber = (NSString *)phoneNumberRef;
    CFRelease(phoneNumberRef);
    CFRelease(locLabel);
    cell.numberLabel.text=phoneNumber;
    cell.boarderButton.layer.borderColor=cell.boarderButton.titleLabel.textColor.CGColor;
    //;
    return cell;
}

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

   ;
   NSString *dest=NULL;;
   CFStringRef valueRef = ABMultiValueCopyValueAtIndex(self.phoneNumbers, indexPath.row);
   if(valueRef != NULL) {
         dest = ;
         CFRelease(valueRef);
   }
    if(dest != nil) {
      NSLog(@&#34;touch2 cell baby&#34;);
      NSString *displayName = ;
      DialerViewController *controller = DYNAMIC_CAST([ changeCurrentView:], DialerViewController);
      if(controller != nil) {
            ;
      }
    }
}
</code></pre>

<p>SecondTableview(ContactProfileviewcontroller) 的 UIViewController 方法:</p>

<pre><code>-(void)viewDidAppear:(BOOL)animated{

}

-(void)viewWillAppear:(BOOL)animated
{

      ;
    //    ;
}



- (void)viewDidLoad {
    ;

    self.phoneNumbers = ABRecordCopyValue((__bridge ABRecordRef)(self.person), kABPersonPhoneProperty);

}

- (void)viewDidDisappear:(BOOL)animated {
   ;
}
</code></pre>

<p>在 FirstTableviewController 中:</p>

<pre><code>- (void)viewDidLoad {
    ;

    ;

    // Set selected+over background: IB lack !
   
               forState:(UIControlStateHighlighted | UIControlStateSelected)];

    objectForInfoDictionaryKey:@&#34;CFBundleDisplayName&#34;]
                  forState:UIControlStateNormal];

    ;

    // Set selected+over background: IB lack !
   
                  forState:(UIControlStateHighlighted | UIControlStateSelected)];

    ;

    (tableController.tableView).backgroundColor = ; // Can&#39;t do it in Xib: issue with ios4
    ; // Can&#39;t do it in Xib: issue with ios4
}
</code></pre>

<p>//——--------</p>

<pre><code>- (void)viewDidAppear:(BOOL)animated {
    ;
    if(!) {
      UIAlertView* error = [ initWithTitle:NSLocalizedString(@&#34;Address book&#34;,nil)
                                                      message:NSLocalizedString(@&#34;You must authorize the application to have access to address book.\n&#34;
                                                                                  &#34;Toggle the application in Settings &gt; Privacy &gt; Contacts&#34;,nil)
                                                       delegate:nil
                                              cancelButtonTitle:NSLocalizedString(@&#34;Continue&#34;,nil)
                                              otherButtonTitles:nil];
      ;
      ;
    //me
    //    [ changeCurrentView:];

       // ;
       ;


    }
}
</code></pre>

<p> <a href="/image/yqaXS.png" rel="noreferrer noopener nofollow"><img src="/image/yqaXS.png" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>发生这种情况是因为您将相同的数据源绑定(bind)到两个 TableView 。你可以在你的 cellforRow 和 didSelect 中做。检查您正在使用的 tableview 并相应地执行操作。 </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在 didSelectRowAtIndexPath 执行后 UITableViewCells 消失了吗?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/47449228/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/47449228/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在 didSelectRowAtIndexPath 执行后 UITableViewCells 消失了吗?