質問してコードを投稿するのはこれが初めてなので、必要なものがすべて含まれていることを願っています。
他のいくつかのアプリでは、UITableView で reloadData を正常に処理できましたが、何らかの理由でここで機能させることができません。
私はnavigationControllerを使用しており、新しいクラスがロードされるまでUITableViewのいくつかのレベルをドリルダウンしています。これには、2つの同様のplistファイルを切り替える2つのボタンしかないため、tableViewが実際にリロードされていることがわかります(Data.plist & Data2. plist)
これは最終的に、個々のジョブがリストされ、ユーザー (ドライバー) がイン/アウト ボタンでタイムクロックをパンチする、タイムシートのようなアプリになる予定です。今のところ、ドリルダウンして他の plist をロードするボタンをクリックし、戻って新しい plist データがロードされたことを確認します。私の問題は、tableView をまったくリロードできないことです。[self.tableView reloadData] と [myTableView reloadData] (IB 経由でも接続しています) のさまざまなバリエーションをあちこちに配置しようとしましたが、どれも機能しません。私は現在、detailViewController (ボタンがある場所) から rootViewController (tableView がある場所) のメソッドを呼び出しており、navigationController が使用されていない場合、その基本的なプロセスは他のアプリで機能します。このアプリでは、navigationController が私を混乱させているようです。簡単な解決策が見つかることを願っています。これまでの私のコードは次のようになります。
AppDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
RootViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
//THIS ESTABLISHES WHICH PLIST TO LOAD BASED ON THE BUTTON CLICKED
plistToUse = [[NSUserDefaults standardUserDefaults] objectForKey:@"plistToUse"];
if (plistToUse == @"Data.plist") {
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"Data.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];
} else if (plistToUse == @"Data2.plist") {
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"Data2.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];
} else {
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"Data.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];
}
if(CurrentLevel == 0) {
NSArray *tempArray = [[NSArray alloc] init];
self.tableDataSource = tempArray;
[tempArray release];
self.tableDataSource = [self.data objectForKey:@"Rows"];
self.navigationItem.title = @"Choose Driver";
} else if (CurrentLevel == 1) {
self.navigationItem.title = @"Choose Day";
} else if (CurrentLevel == 2) {
self.navigationItem.title = @"Choose Job";
} else if (CurrentLevel == 3) {
self.navigationItem.title = @"Job Details";
} else {
self.navigationItem.title = CurrentTitle;
}
}
-(void)update {
dvController.labelHelper.text = @"UPDATED"; //USED TO SEE IF A LABEL IN THE BUTTON CLASS WILL UPDATE
NSArray *tempArray = [[NSArray alloc] init];
self.tableDataSource = tempArray;
[tempArray release];
self.tableDataSource = [self.data objectForKey:@"Rows"];
self.navigationController.navigationItem.title = @"Choose Driver";
self.navigationController.title = @"THE TITLE";
[myTableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
unsortedIndex=1;
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.tableDataSource count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
cell.textLabel.text = [dictionary objectForKey:@"Title"];
NSArray *Children = [dictionary objectForKey:@"Children"];
if ([Children count] == 0) {
Titles = [dictionary objectForKey:@"Title"];
in1 = [[NSUserDefaults standardUserDefaults] objectForKey:@"InTime1"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", in1];
}
in1 = [[NSUserDefaults standardUserDefaults] objectForKey:@"InTime1"];
out1 = [[NSUserDefaults standardUserDefaults] objectForKey:@"OutTime1"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@:%@", in1, out1];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
NSArray *Children = [dictionary objectForKey:@"Children"];
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
if([Children count] == 0) {
[self.navigationController pushViewController:dvController animated:YES];
dvController.labelSiteName.text = [dictionary objectForKey:@"Company"];
dvController.labelSiteAddress.text = [dictionary objectForKey:@"Address"];
dvController.labelSiteNotes.text = [dictionary objectForKey:@"Notes"];
[dvController.mapView setMapType:MKMapTypeStandard];
[dvController.mapView setZoomEnabled:YES];
[dvController.mapView setScrollEnabled:YES];
dvController.mapView.showsUserLocation = YES;
[dvController release];
}
else {
RootViewController *rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
rvController.CurrentLevel += 1;
rvController.CurrentTitle = [dictionary objectForKey:@"Title"];
[self.navigationController pushViewController:rvController animated:YES];
rvController.tableDataSource = Children;
[rvController release];
}
}
DetailViewController.m これらは、Data.plist または Data2.plist のいずれかで tableView をリロードする必要がある 2 つのボタンです。
-(IBAction)getInTime1:(id)sender {
plistToUse = @"Data.plist";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:plistToUse forKey:@"plistToUse"];
[defaults synchronize];
[rvController update];
}
-(IBAction)getOutTime1:(id)sender {
plistToUse = @"Data2.plist";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:plistToUse forKey:@"plistToUse"];
[defaults synchronize];
[rvController update];
}
私はあなたが与えることができる任意の助けに感謝します.