• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-11 19:21:15 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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


附:

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


第一个UITableView:

- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

    static NSString *kCellId = @"UIContactCell";

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

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

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

    image = [UIImage imageWithDataNSData *)imageData];


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

    if(image == nil) {
        //image = [UIImage imageNamed"avatar_unknown_small.png"];
        RandomColor *random=[[RandomColor alloc] init];
        cell.avatarImage.backgroundColor=[random makeColor:[NSString stringWithFormat"%@ %@",name,family]];

        cell.imageView.image=nil;
        // cell.imageView.backgroundColor=[UIColor whiteColor];

        cell.imageLabel.alpha=1;

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

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


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


- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName"DialerStoryboard" bundle:nil];
    ContactProfileViewController *nextview = [storyboard instantiateViewControllerWithIdentifier"rofile"];
    OrderedDictionary *subDic = addressBookMap[[addressBookMap keyAtIndex: indexPath.section]];
    ABRecordRef lPerson = subDic[[subDic keyAtIndex:indexPath.row]];
    // ContactProfileViewController *nextview=[[ContactProfileViewController alloc] init];
    nextview.person=lPerson;
    [self presentViewController:nextview animated:YES completion:^{

    }];
}

第二个UITableView:

-(UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath{
    AddContactTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier"mesal" forIndexPath:indexPath];
    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;
    //[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {

     [tableView deselectRowAtIndexPath:indexPath animated:YES];
     NSString *dest=NULL;;
     CFStringRef valueRef = ABMultiValueCopyValueAtIndex(self.phoneNumbers, indexPath.row);
     if(valueRef != NULL) {
         dest = [ContactProfileViewController localizeLabel:(NSString*) valueRef];
         CFRelease(valueRef);
     }
    if(dest != nil) {
        NSLog(@"touch2 cell baby");
        NSString *displayName = [FastAddressBook getContactDisplayName:person];
        DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[DialerViewController compositeViewDescription]], DialerViewController);
        if(controller != nil) {
            [controller call:dest displayName:displayName];
        }
    }
}

SecondTableview(ContactProfileviewcontroller) 的 UIViewController 方法:

-(void)viewDidAppear:(BOOL)animated{

}

-(void)viewWillAppear:(BOOL)animated
{

        [super viewDidDisappear:animated];
    //    [_tableView reloadData];
}



- (void)viewDidLoad {
    [super viewDidLoad];

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

  }

- (void)viewDidDisappear:(BOOL)animated {
   [super viewDidDisappear:animated];
}

在 FirstTableviewController 中:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self changeView:History_All];

    // Set selected+over background: IB lack !
    [linphoneButton setBackgroundImage:[UIImage imageNamed"buttonR"]
                 forState:(UIControlStateHighlighted | UIControlStateSelected)];

    [linphoneButton setTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey"CFBundleDisplayName"]
                    forState:UIControlStateNormal];

    [LinphoneUtils buttonFixStates:linphoneButton];

    // Set selected+over background: IB lack !
    [allButton setBackgroundImage:[UIImage imageNamed"buttonch2"]
                    forState:(UIControlStateHighlighted | UIControlStateSelected)];

    [LinphoneUtils buttonFixStates:allButton];

    (tableController.tableView).backgroundColor = [UIColor clearColor]; // Can't do it in Xib: issue with ios4
    [tableController.tableView setBackgroundView:nil]; // Can't do it in Xib: issue with ios4
}

//——--------

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if(![FastAddressBook isAuthorized]) {
        UIAlertView* error = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Address book",nil)
                                                        message:NSLocalizedString(@"You must authorize the application to have access to address book.\n"
                                                                                  "Toggle the application in Settings > Privacy > Contacts",nil)
                                                       delegate:nil
                                              cancelButtonTitle:NSLocalizedString(@"Continue",nil)
                                              otherButtonTitles:nil];
        [error show];
        [error release];
    //me
    //    [[PhoneMainView instance] changeCurrentView:[DialerViewController compositeViewDescription]];

       // [self presentViewController:error animated:YES completion:nil];
       [PhoneMainView.instance popCurrentView];


    }
}

enter image description here



Best Answer-推荐答案


发生这种情况是因为您将相同的数据源绑定(bind)到两个 TableView 。你可以在你的 cellforRow 和 didSelect 中做。检查您正在使用的 tableview 并相应地执行操作。

关于ios - 在 didSelectRowAtIndexPath 执行后 UITableViewCells 消失了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47449228/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap