gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:06:02 31 4
gpt4 key购买 nike

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


附言:

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


第一个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:^{

}];
}

第二个UITableView:

-(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 方法:

-(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

最佳答案

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

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

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com