ios - Storyboard和程序化 View

标签 ios uiview storyboard xib

我完全迷失在这个问题上。我一直在使用 Storyboard,我创建了一个带有表格 View 和一些东西的导航 Controller 。有Services在 tableview 的每一行中,我需要为每个服务创建一个详细 View 。

有很多服务,所以我无法在 Storyboard 中创建它们。这个想法是下载Services来自网络服务(参数数量、每个参数的类型等),并根据需要添加为文本字段/按钮到 Service .

所以,我的问题和疑问是:

1)我可以以编程方式组合 Storyboard和 View 吗?当我创建 NewViewMyTableviewClass ,我应该在我的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:

**enter image description here**

第二步:

返回您的StoryBoard并单击场景使其被选中。接下来,点击Files Owner最后点击类信息按钮(第三个按钮),最后选择你的ServiceViewController您刚刚创建的类(class)。

enter image description here

第三步:

回到您的ServicesViewControllerdidSelectRowAtIndex方法调用你的序列:

- (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/

相关文章:

ios - IOS 中启动屏幕和初始屏幕之间的故障

iphone - 在 Storyboard 中将核心数据与选项卡栏 Controller 一起使用

ios - 'top-level directory'(应用程序包上下文)是什么意思?

ios - 如何让 iTunes Connect 识别新的 Bundle ID

ios - 获取 UIPageViewController 的滚动位置

c# - MonoTouch - UIView.Animate 完成回调未在按钮 touchUpInside 委托(delegate)内调用

uiview - @IBInspectable 不更新 Storyboard

android - Android RelativeLayout/LinearLayout 的 iOS 等价物是什么?

ios - 拖动时调整 UIView 框架

iOS 通用应用程序 - 启动时出现空白屏幕