【发布时间】:2018-05-25 13:58:12
【问题描述】:
好的,所以在 IB 中,我为 iPhone 版本创建了一个带有 tableview 的 ViewController,效果很好。
在 iPad 版本上,如果它只是文本,你就不能让 tableview 占据整个屏幕。因此,在 iPad Storyboard 中,我在主视图控制器上创建了一个按钮,该按钮通过 tableview 连接到自定义 ViewController,并以弹出窗口的形式打开。
打开得很好,数据正在从带有 tableview 的 ViewController 传递到主视图。在控制台中,我看到标签正在更新,但在屏幕上标签没有更新。
在我用来检索数据的方法中尝试了[self.view layoutIfNeeded],按照某些人在其他答案中的建议更改了 alpha。我注意到 viewWillAppear 根本没有被调用。尝试将 didSelectRowAtIndex 中的 main vc viewWillAppear 设置为 yes...
当我转到另一个屏幕并返回时,标签当然会更新。
这是我在选择弹出窗口中的单元格时使用 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]];
}];
}
}
这是上面调用的 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);
}
【问题讨论】:
-
你能说明你从哪里得到
vc值吗? -
@trungduc 我实例化了主 ViewController。
ViewController *vc = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? (ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewControlleriPad"] : (ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; -
请显示方法的完整代码你在哪里调用它
-
@trungduc 编辑的问题,因为它在 cmets 中太混乱了
-
好的,我明白了。还有一个问题。据我了解,当前视图控制器由
ViewController呈现,现在您想要关闭当前控制器并更新ViewController。对吗?
标签: ios objective-c uitableview uilabel popover