项目进入测试阶段,偷得半日闲整理这篇博客,码字不容易,喜欢转载请大家标明出处:http://blog.youkuaiyun.com/wangtie_123/article/details/36179191
UIStoryBoard 使用条件:
UIStoryBoard的特性:
UIStoryBoard--传值和逻辑处理
两个方法执行在页面跳转开始到下一个界面ViewDidLoad之前
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender NS_AVAILABLE_IOS(6_0); // Invoked immediately prior to initiating a segue. Return NO to prevent the segue from firing. The default implementation returns YES. This method is not invoked when -performSegueWithIdentifier:sender: is used.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender NS_AVAILABLE_IOS(5_0);
-(BOOL)checkTextFild{
if ([self.userTF.text isEqualToString:@""]) {
return NO;
}
if ([self.passwordTF.text isEqualToString:@""]) {
return NO;
}
return YES;
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
[segue.destinationViewController setUserNameString:self.userTF.text];
[segue.destinationViewController setPasswordString:self.passwordTF.text];
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender{
return [self checkTextFild];
}
注:.shouldPerformSegueWithIdentifier 方法如果返回no,页面则不会跳转。
UIStoryBoard--UIStoryboardSegue
@property (nonatomic, readonly) NSString *identifier;
@property (nonatomic,readonly)id sourceViewController;
@property (nonatomic,readonly)id destinationViewController;
1.首先什么是UIStoryboardSegue,就是ViewController 之间的“联线” ,
2.identifier 属性不用多说就是标示,设置的地方在storyboard中点击线条,然后在右面Attributes inspector中可看到有一个输入框对应identifier,一个选择框对用style(就是联接方式)
3.sourceViewController 和destinationViewController 分别指联接的前一个viewController 和后一个viewController
应用实例代码:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _objects[indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}else if([[segue identifier] isEqualToString:@"showOther"]){
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _objects[indexPath.row];
[[segue destinationViewController] setOtherItem:object];
}
}
这个逻辑结构参照第一张图,在tableview中定义两个cell,分别跳转到不同的viewCtroller,跳转时根据identifier调用对应方法。
Demo 下载地址:http://download.youkuaiyun.com/detail/wangtie_123/7576499
好了,以上就是UIStroryboard的基本应用。如果有什么没有表示清楚或者不解的地方,欢迎大家评论交流。