我完全迷失在这个问题上。我一直在使用 Storyboard,我创建了一个带有表格 View 和一些东西的导航 Controller 。有Services
在 tableview 的每一行中,我需要为每个服务创建一个详细 View 。
有很多服务,所以我无法在 Storyboard 中创建它们。这个想法是下载Services
来自网络服务(参数数量、每个参数的类型等),并根据需要添加为文本字段/按钮到 Service
.
所以,我的问题和疑问是:
1)我可以以编程方式组合 Storyboard和 View 吗?当我创建 NewView
在 MyTableviewClass
,我应该在我的prepareforsegue
中进行吗?方法?如何在不丢失导航 Controller 的情况下在屏幕上显示它?这就是我所拥有的(它不起作用:它告诉我没有名称为 'Service1' 的segue):
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
if ([[segue identifier] isEqualToString:@"NextLevel"]) {
[segue.destinationViewController setActualNodo:[actualNodo getSonAtIndex:indexPath.row]];
} else if ([[segue identifier] isEqualToString:@"Service1"]) {
CGRect bounds = self.view.bounds;
UIView *myview = [[UIView alloc] initWithFrame:bounds];
[myview setBackgroundColor: [UIColor redColor]];
[self.view addSubview:myview];
[self.view bringSubviewToFront:myview]; }
欢迎任何书籍或引用资料,但我找不到类似的东西。这在iOS中非常复杂吗?我在 Java 中做过类似的事情。我已经阅读了有关使用 XIB 动态生成接口(interface)的信息,但是说实话,我不知道它是什么..
谢谢大家。
最佳答案
是的,您可以创建 StoryBoard
有一个 View ,然后以编程方式向它添加 View 。
您不应该尝试在 prepareForSegue
中创建 View 。方法。这确实应该用于将对象传递给另一个 ViewController
.
我会向你推荐这个。返回您的StoryBoard
并创建一个新的 UIViewController 场景。点击你的第一个场景和CTRL
拖动到新场景。接下来,单击您的 segue 并为其命名。
第一步:
创建一个名为 的新类服务 View Controller 并确保它是 `UIViewController:
第二步:
返回您的StoryBoard
并单击场景使其被选中。接下来,点击Files Owner
最后点击类信息按钮(第三个按钮),最后选择你的ServiceViewController
您刚刚创建的类(class)。
第三步:
回到您的ServicesViewController
在 didSelectRowAtIndex
方法调用你的序列:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"YOUR_SEGUE_NAME" sender:nil];
}
现在,清除
prepareForSegue
中的所有代码方法,然后首先将过渡降下来。
关于ios - Storyboard和程序化 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16468401/