Ios 执行didSelectRowAtIndexPath后,UITableViewCells是否消失?

Ios 执行didSelectRowAtIndexPath后,UITableViewCells是否消失?,ios,objective-c,uitableview,tableview,didselectrowatindexpath,Ios,Objective C,Uitableview,Tableview,Didselectrowatindexpath,我有两个表视图,在第一个UITableView(联系人表视图)中,加载了所有单元格,当我触摸单元格时,它将转到详细联系人,一切正常。 在第二个UITableView(详细联系人)中,当我触摸手机(呼叫联系人)和第二个UITableView方法didSelectRowAtIndexPath执行时,它工作,但会导致第一个UITableView中的所有数据(联系人)消失。我怎样才能解决这个问题 附言: (如果我在第二个UITableView中禁用didSelectRowAtIndexPath,数据将

我有两个表视图,在第一个
UITableView
(联系人表视图)中,加载了所有单元格,当我触摸单元格时,它将转到详细联系人,一切正常。 在第二个
UITableView
(详细联系人)中,当我触摸手机(呼叫联系人)和第二个
UITableView
方法
didSelectRowAtIndexPath
执行时,它工作,但会导致第一个
UITableView
中的所有数据(联系人)消失。我怎样才能解决这个问题


附言:

(如果我在第二个
UITableView
中禁用
didSelectRowAtIndexPath
,数据将保留在第一个表视图中) (表视图之间没有分段)


第一个
UITableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)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 setBackgroundColor:LINPHONE_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 imageWithData:(NSData *)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 imageWithData:(NSData *)imageData1];

    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 = [UIStoryboard storyboardWithName:@"DialerStoryboard" bundle:nil];
    ContactProfileViewController *nextview = [storyboard instantiateViewControllerWithIdentifier:@"Profile"];
    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:^{

    }];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)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)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)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];
        }
    }
}
第二个
UITableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)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 setBackgroundColor:LINPHONE_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 imageWithData:(NSData *)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 imageWithData:(NSData *)imageData1];

    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 = [UIStoryboard storyboardWithName:@"DialerStoryboard" bundle:nil];
    ContactProfileViewController *nextview = [storyboard instantiateViewControllerWithIdentifier:@"Profile"];
    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:^{

    }];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)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)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)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方法:

在FirstTableviewController中:

-(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];
}
- (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];


    }
}

发生这种情况是因为两个表视图都绑定了相同的数据源。你所能做的就是在你的手机里按FORROW和didSelect。检查您正在使用的tableview并执行相应的操作

数组正在初始化的位置,是在viewdidload中,还是view将出现在firstTableView中,是否可以添加视图代码?FirstView的didload检查第一个tableview的数据源数组。