以前写程序基本用纯代码 现在流行了故事版的和IB的来写,故事版和IB一起来写整个界面显得简单工程里的代码明显少了,但是功能一点没少既然Xcode6在建工程的时候已经自动为我们生成了一个storyboard和IB文件 这说明苹果官方是推荐我们使用故事版和IB的.因为这样开发起来项目周期短,效率高.随之而来的是维护性差,因为在维护的过程中你需要自己理清开发者的设计思路,每个地方的关联性比较强有时候可能你一个小控件做出修改了.其让地方都出现一定的影响.
最近自己做了一些小测试 下面把测试的结果贴出来 希望遇到同样问题的朋友可以解决.
测试版本xcode6.1

建一个工程 工程里添加故事版所需的controller 框架搭建.
xib负责页面实现.
在相应的.m文件中写入一下方法
- (void)awakeFromNib
{
[[NSBundlemainBundle] loadNibNamed:@"MyViewController"owner:selfoptions:nil];
} 这样就把storyboard 中的controller和xib中的controller关联起来了.
使用xib主要是页面的布局.使用故事版主要是进行大框架的搭建.当然故事版也可以进行页面布局,自己还没有使用过,以后会尝试进行一些操作.
在使用storyboard 和xib混用的过程中我们可能会遇到这样的问题,我想跳转到某个视图控制器可是我在storyboard中没有拉线到某个视图控制器。那么有什么好的解决办法呢
从storyboard 跳到 另一个storyboard或者当前storyboard
方法:
//第一步 找到目标的storyboard
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//第二步 在目标的storyboard中根据viewcontroller的id 找到对应的controller
这点需要注意如果你要在storyboard中 存在 然后才能找到。如果使用alloc init 那就是创建一个新的controller 不是由storyboard 得到的controller
TestViewController *myVC = [mainStoryboard instantiateViewControllerWithIdentifier:@"TestViewController"];
//传值
myVC.itemDic = _dict;
//第三步 push 跳转到指定的页面.
[self.navigationController pushViewController:myVC animated:YES];
使用xib
//第一步:
通过nib名字 找到controller
TestViewController *testVC = [[TestViewController alloc]initWithNibName:@"TestViewController" bundle:nil];
//传值
//第二步 push跳转到指定的页面.
[self.navigationController pushViewController:testVC animated:YES]; //通过nib找到UITableviewCell
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"MyTableViewCell" owner:self options:nil];
for (id oneObject in nib) {
if ([oneObject isKindOfClass:[MyTableViewCell class]])
cell = (MyTableViewCell *)oneObject;
}
|