好的,因此在IB中,我创建了一个带有iPhone版本的tableview的ViewController,并且效果很好。
在iPad版本上,如果只有文字,您就无法让TableView占用整个屏幕。因此,在iPad故事板中,我在主视图控制器上创建了一个按钮,该按钮与TableView连接到自定义ViewController,然后以弹出速度打开。
打开很棒的,数据正在从controller传递给主浏览器。在控制台中,我看到该标签正在更新,但是在屏幕上,标签不会更新。
在我用来检索数据的方法中尝试了[self.view layoutIfNeeded]
,就像其他答案中的某些人所建议的那样更改alpha。我注意到ViewWillAppear根本没有被调用。尝试将DidSelectRowatex中的Main VC ViewWillAppear设置为是...
当我回到另一个屏幕回来时,标签会更新。
这是我在选择弹出窗口中选择一个单元格时用tableview解雇视图控制器的方式。
[self dismissViewControllerAnimated:YES completion:^{
[vc viewWillAppear:YES];
[vc.view layoutIfNeeded];
[vc updateText:[arrUsers objectAtIndex:indexPath.row]];
}];
我正在将其解雇以防止主视图控制器更新吗?
这是弹出案中的方法:
- (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]];
}];
}
}
这是上面称为视图控制器中的方法。
-(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];