だから、私は にUITableView
ロードされていUIViewController
ます。テーブルはデータを取得しますNSMutableArray
に を追加しUIBarButtonItem
ました。NavigationBar
これABPeoplePickerNavigationController
により、連絡先を選択し、その名前を に追加してNSMutableArray
、UITableView
これは私のコードの要約です
@interface LockedChatsTableView : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, ABPeoplePickerNavigationControllerDelegate>
@property (strong, nonatomic, retain) UITableView *tabView;
@property (strong, nonatomic) NSMutableArray *listArray;
@end
@implementation LockedChatsTableView
- (void)viewDidLoad {
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showPicker:)];
self.navigationItem.rightBarButtonItem = addButton;
self.navigationItem.title = @"Locked Chats";
[self.listArray removeAllObjects];
[self.view setBackgroundColor:[UIColor whiteColor]];
CGFloat width = [UIScreen mainScreen].bounds.size.width;
CGFloat height = [UIScreen mainScreen].bounds.size.height;
self.tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
self.tabView.alwaysBounceVertical = NO;
self.tabView.delegate = self;
self.tabView.dataSource = self;
self.listArray = [[NSMutableArray alloc] init];
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:[self path]];
self.listArray = [data objectForKey:@"LockedChats"];
[self.view addSubview:self.tabView];
}
// .... some tableview delegate method ....
-(void)addChatWithName:(NSString *)chatName {
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:[self path]];
NSMutableArray *lockedChats = [data objectForKey:@"LockedChats"];
[lockedChats addObject:chatName];
[data setObject:lockedChats forKey:@"LockedChats"];
[data writeToFile:[self path] atomically:YES];
}
-(void)removeChatWithName:(NSString *)chatName {
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:[self path]];
NSMutableArray *lockedChats = [data objectForKey:@"LockedChats"];
[lockedChats removeObject:chatName];
[data setObject:lockedChats forKey:@"LockedChats"];
[data writeToFile:[self path] atomically:YES];
}
// ====================== Contact Picker ======================== //
- (void)showPicker:(UIBarButtonItem *)sender {
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
NSString* name = (__bridge NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString* lastname = (__bridge NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
[self addChatWithName:[NSString stringWithFormat:@"%@ %@",name,lastname]];
[self dismissViewControllerAnimated:YES completion:nil];
// [self.tabView performSelectorOnMainThread:@selector(reloadData) withObject:nil];
// [self.tabView reloadData];
return NO;
}
// .... some other people picker delegate method ....
@end
だから私の問題は、連絡先を選択してその名前を配列に保存すると、UITableView
リロードされないことです! 私は文字通りすべてのソリューションを試しました:
私は
[self.tabView reloadData];
多くの異なる場所で試してみましたが、うまくいきませんでした (メインスレッドの外側にあるためでしょうか?)私も試し
[self.tabView performSelectorOnMainThread:@selector(reloadData) withObject:nil];
ましたが、テーブルをリロードしませんでした。私は運が悪く、stackoverflowで見つかった他の多くの答えを試してみました
私は考えが及ばず、この小さな問題に一日中取り組んでいます! あなたの助けは大歓迎です。