-2

文件组织

在我的项目中,应用程序在 ViewController 中启动,通过将其添加为子视图(ViewController.h - [self.view addSubview: Table.tableView];)加载到表(表类)中

Camera Class 是详细视图,因此当您点击表格行时,它会加载 Camara.xib。直到这里一切正常。

当我尝试关闭 Camera.xib 并返回 ViewController.xib 时,问题就出现了,当我这样做时,Camera.xib 关闭正常,但不是返回 ViewController.xib 里面有 Table.xib,应用程序只加载 Table .xib,因此放置在 ViewController.xib 视图中的其余对象不会显示。

我究竟做错了什么?

提前致谢!!

代码:

表.m

- (void)viewDidLoad
{

    roomsArray = [[NSMutableArray alloc] initWithObjects:nil];
    [super viewDidLoad];

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // my code...

    Camara *camara = [[Camara alloc] initWithNibName:@"Camara" bundle:nil];
    [self presentViewController:camara animated:YES completion:nil];

}

卡马拉.m

-(IBAction)cancel:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

视图控制器.m

- (void)viewDidLoad
{

    table = [[Table alloc] initWithNibName:@"Table" bundle:nil];

    [windows.tableView reloadData];
    [self.view addSubview:windows.tableView];
    windows.tableView.transform = CGAffineTransformMakeTranslation(0, 44);

    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

}

4

3 回答 3

1

在没有看到您正在使用的代码的情况下,我无法完全回答,但我的猜测是您需要在 viewWillAppear 中添加一些东西来重新加载您的表格或表格 xib。每次关闭您的模式时都会调用 viewWillAppear。

另一种选择是创建一个委托协议,以允许您的模态控制器调用初始视图控制器上的方法。

这是一篇很好的文章:https ://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

于 2013-08-26T18:29:45.897 回答
0

首先,我必须说明您的问题已被否决,很可能是因为它的英文写得很差,而且最初它缺乏解决方案所需的必要信息。

接下来,我想强调的是,诸如此类的超级调用[super viewDidLoad]应始终位于任何代码逻辑之前。将它们移到每个方法的顶部。

现在至于为什么你有问题。

每当在内存中创建视图控制器时,它将执行其 viewDidLoad 方法,然后在它出现之前执行 viewWillAppear 方法(在其父级上,除非您重载它),该执行仅在视图生命周期中发生一次。任何未来显示视图的尝试都将导致调用 viewWillAppear。

解决方案 移动以下代码

[windows.tableView reloadData];
[self.view addSubview:windows.tableView];
windows.tableView.transform = CGAffineTransformMakeTranslation(0, 44);

进入

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [windows.tableView reloadData];
    [self.view addSubview:windows.tableView];
    windows.tableView.transform = CGAffineTransformMakeTranslation(0, 44);
}
于 2013-08-26T19:11:03.277 回答
0

问题是 tableViewController 和 ViewController 在两个视图控制器中,所以我将它们结合起来,现在一切正常。

于 2013-08-28T23:17:33.917 回答