好吧在IB中,我创建了一个带有iPhone版桌面视图的ViewController,效果很好。
在iPad版本中,如果只有文本,你就无法使用桌面视图占用整个屏幕。 因此,在iPad Storyboard中,我在主视图控制器上创建了一个按钮,该按钮通过tableview连接到自定义ViewController,并以弹出窗口的形式打开。
打开很棒,数据从ViewController传递到tableview到主视图。 在控制台中,我看到标签正在更新,但在屏幕上标签不会更新。
在我用来检索数据的方法中尝试了[self.view layoutIfNeeded] ,像其他答案中的一些人所建议的那样更改了alpha。 我注意到viewWillAppear根本没有被调用。 尝试设置主vc viewWill出现在didSelectRowAtIndex为yes ...
当我去另一个屏幕然后回来时,标签会更新。
这里是我如何在popover中选择一个单元格的时候使用tableview解除视图控制器。
[self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateText:[arrUsers objectAtIndex:indexPath.row]]; }];这是否是我解雇它阻止主视图控制器更新的事实?
这是popover中的方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; UIStoryboard * storyboard = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil] : [UIStoryboard storyboardWithName:@"Main" bundle:nil]; ViewController *vc = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? (ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewControlleriPad"] : (ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if(searching){ if ([copyListOfItems count]>0) { NSLog(@"Search Results Selected %@", [copyListOfItems objectAtIndex:indexPath.row]); [vc.lbl_specialties setText:[copyListOfItems objectAtIndex:indexPath.row]]; } } else { self.appDelegate.selectedSpecialty = [arrUsers objectAtIndex:indexPath.row]; NSLog(@"Selected %@", self.appDelegate.selectedSpecialty); } [self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateSpecialtyText:[arrUsers objectAtIndex:indexPath.row]]; }]; } }这是上面调用的View控制器中的方法。
-(void)updateSpecialtyText:(NSString*)text { [super viewWillAppear:YES]; NSLog(@"text to update %@", text); [self.lbl_specialties layoutIfNeeded]; [self.view layoutIfNeeded]; [self.lbl_specialties setText:text]; NSLog(@"text updated %@", self.lbl_specialties.text); }Ok So in IB I created a ViewController with a tableview for the iPhone version and works great.
On the iPad version you very well can't have a tableview take up the entire screen if its just text. So in the iPad Storyboard I created a button on the main view controller that is connected to the custom ViewController with a tableview and it opens as a popover instead.
Opens up great, data is being passed from the ViewController with the tableview to the main one. In the console, I am seeing the label is being updated, but on screen the label doesn't update.
Tried [self.view layoutIfNeeded] in the method that I used to retrieve the data, changing the alpha as some people suggested in other answers. I noticed the viewWillAppear does not get called at all. Tried setting main vc viewWillAppear in the didSelectRowAtIndex to yes...
The label gets updated of course when I go to another screen and come back.
Here is how I am dismissing the view controller with a tableview upon selecting a cell in the popover.
[self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateText:[arrUsers objectAtIndex:indexPath.row]]; }];Is it the fact that I am dismissing it preventing the main view controller from updating?
This is the method in the popover:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; UIStoryboard * storyboard = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil] : [UIStoryboard storyboardWithName:@"Main" bundle:nil]; ViewController *vc = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? (ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewControlleriPad"] : (ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if(searching){ if ([copyListOfItems count]>0) { NSLog(@"Search Results Selected %@", [copyListOfItems objectAtIndex:indexPath.row]); [vc.lbl_specialties setText:[copyListOfItems objectAtIndex:indexPath.row]]; } } else { self.appDelegate.selectedSpecialty = [arrUsers objectAtIndex:indexPath.row]; NSLog(@"Selected %@", self.appDelegate.selectedSpecialty); } [self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateSpecialtyText:[arrUsers objectAtIndex:indexPath.row]]; }]; } }This is the method in the View controller that is called above.
-(void)updateSpecialtyText:(NSString*)text { [super viewWillAppear:YES]; NSLog(@"text to update %@", text); [self.lbl_specialties layoutIfNeeded]; [self.view layoutIfNeeded]; [self.lbl_specialties setText:text]; NSLog(@"text updated %@", self.lbl_specialties.text); }最满意答案
在我看来,而不是
[self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateText:[arrUsers objectAtIndex:indexPath.row]]; }];你应该试试
[(ViewController *)self.presentingViewController updateText:[arrUsers objectAtIndex:indexPath.row]]; [self dismissViewControllerAnimated:YES completion:nil];如果ViewController嵌入到UINavigationController ,请改为使用下面的代码。
[(ViewController *)[(UINavigationController *)self.presentingViewController topViewController] updateText:[arrUsers objectAtIndex:indexPath.row]]; [self dismissViewControllerAnimated:YES completion:nil];In my opinion, instead of
[self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateText:[arrUsers objectAtIndex:indexPath.row]]; }];you should try
[(ViewController *)self.presentingViewController updateText:[arrUsers objectAtIndex:indexPath.row]]; [self dismissViewControllerAnimated:YES completion:nil];If ViewController is embedded in an UINavigationController, use the code below instead.
[(ViewController *)[(UINavigationController *)self.presentingViewController topViewController] updateText:[arrUsers objectAtIndex:indexPath.row]]; [self dismissViewControllerAnimated:YES completion:nil];在Popover tableview中选择单元格后,UILabel不会刷新(UILabel not refreshing after selecting cell in Popover tableview)好吧在IB中,我创建了一个带有iPhone版桌面视图的ViewController,效果很好。
在iPad版本中,如果只有文本,你就无法使用桌面视图占用整个屏幕。 因此,在iPad Storyboard中,我在主视图控制器上创建了一个按钮,该按钮通过tableview连接到自定义ViewController,并以弹出窗口的形式打开。
打开很棒,数据从ViewController传递到tableview到主视图。 在控制台中,我看到标签正在更新,但在屏幕上标签不会更新。
在我用来检索数据的方法中尝试了[self.view layoutIfNeeded] ,像其他答案中的一些人所建议的那样更改了alpha。 我注意到viewWillAppear根本没有被调用。 尝试设置主vc viewWill出现在didSelectRowAtIndex为yes ...
当我去另一个屏幕然后回来时,标签会更新。
这里是我如何在popover中选择一个单元格的时候使用tableview解除视图控制器。
[self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateText:[arrUsers objectAtIndex:indexPath.row]]; }];这是否是我解雇它阻止主视图控制器更新的事实?
这是popover中的方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; UIStoryboard * storyboard = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil] : [UIStoryboard storyboardWithName:@"Main" bundle:nil]; ViewController *vc = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? (ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewControlleriPad"] : (ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if(searching){ if ([copyListOfItems count]>0) { NSLog(@"Search Results Selected %@", [copyListOfItems objectAtIndex:indexPath.row]); [vc.lbl_specialties setText:[copyListOfItems objectAtIndex:indexPath.row]]; } } else { self.appDelegate.selectedSpecialty = [arrUsers objectAtIndex:indexPath.row]; NSLog(@"Selected %@", self.appDelegate.selectedSpecialty); } [self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateSpecialtyText:[arrUsers objectAtIndex:indexPath.row]]; }]; } }这是上面调用的View控制器中的方法。
-(void)updateSpecialtyText:(NSString*)text { [super viewWillAppear:YES]; NSLog(@"text to update %@", text); [self.lbl_specialties layoutIfNeeded]; [self.view layoutIfNeeded]; [self.lbl_specialties setText:text]; NSLog(@"text updated %@", self.lbl_specialties.text); }Ok So in IB I created a ViewController with a tableview for the iPhone version and works great.
On the iPad version you very well can't have a tableview take up the entire screen if its just text. So in the iPad Storyboard I created a button on the main view controller that is connected to the custom ViewController with a tableview and it opens as a popover instead.
Opens up great, data is being passed from the ViewController with the tableview to the main one. In the console, I am seeing the label is being updated, but on screen the label doesn't update.
Tried [self.view layoutIfNeeded] in the method that I used to retrieve the data, changing the alpha as some people suggested in other answers. I noticed the viewWillAppear does not get called at all. Tried setting main vc viewWillAppear in the didSelectRowAtIndex to yes...
The label gets updated of course when I go to another screen and come back.
Here is how I am dismissing the view controller with a tableview upon selecting a cell in the popover.
[self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateText:[arrUsers objectAtIndex:indexPath.row]]; }];Is it the fact that I am dismissing it preventing the main view controller from updating?
This is the method in the popover:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; UIStoryboard * storyboard = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil] : [UIStoryboard storyboardWithName:@"Main" bundle:nil]; ViewController *vc = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? (ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewControlleriPad"] : (ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if(searching){ if ([copyListOfItems count]>0) { NSLog(@"Search Results Selected %@", [copyListOfItems objectAtIndex:indexPath.row]); [vc.lbl_specialties setText:[copyListOfItems objectAtIndex:indexPath.row]]; } } else { self.appDelegate.selectedSpecialty = [arrUsers objectAtIndex:indexPath.row]; NSLog(@"Selected %@", self.appDelegate.selectedSpecialty); } [self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateSpecialtyText:[arrUsers objectAtIndex:indexPath.row]]; }]; } }This is the method in the View controller that is called above.
-(void)updateSpecialtyText:(NSString*)text { [super viewWillAppear:YES]; NSLog(@"text to update %@", text); [self.lbl_specialties layoutIfNeeded]; [self.view layoutIfNeeded]; [self.lbl_specialties setText:text]; NSLog(@"text updated %@", self.lbl_specialties.text); }最满意答案
在我看来,而不是
[self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateText:[arrUsers objectAtIndex:indexPath.row]]; }];你应该试试
[(ViewController *)self.presentingViewController updateText:[arrUsers objectAtIndex:indexPath.row]]; [self dismissViewControllerAnimated:YES completion:nil];如果ViewController嵌入到UINavigationController ,请改为使用下面的代码。
[(ViewController *)[(UINavigationController *)self.presentingViewController topViewController] updateText:[arrUsers objectAtIndex:indexPath.row]]; [self dismissViewControllerAnimated:YES completion:nil];In my opinion, instead of
[self dismissViewControllerAnimated:YES completion:^{ [vc viewWillAppear:YES]; [vc.view layoutIfNeeded]; [vc updateText:[arrUsers objectAtIndex:indexPath.row]]; }];you should try
[(ViewController *)self.presentingViewController updateText:[arrUsers objectAtIndex:indexPath.row]]; [self dismissViewControllerAnimated:YES completion:nil];If ViewController is embedded in an UINavigationController, use the code below instead.
[(ViewController *)[(UINavigationController *)self.presentingViewController topViewController] updateText:[arrUsers objectAtIndex:indexPath.row]]; [self dismissViewControllerAnimated:YES completion:nil];
发布评论