IOS7 随记(一)之unwind segue

本文介绍了iOS开发中的几个实用技巧,包括使用AutoLayout进行界面布局、利用unwind segue实现导航返回、在Mac上截图并转换格式的方法、静态显示UITableView的内容以及Objective-C中正确的返回类型使用。这些技巧有助于提高开发效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于auto lay out,unwind segue,tiff,静态显示tableView内容,返回类型:instancetype and id

1.Auto Lay Out:

    a.选中控件,control-dray,分别从四个方向释放鼠标,会出现相对应方向的关于constraint的shortcut菜单

    b.或是从顶部菜单 Editor - Resolve Auto Layout Issues - Reset to Suggested Constraints

                 Editor - Resolve Auto layout Issues - Clear Constraints

2.unwind segue to navigate back:

    a-push/modal segue to-b,b-unwind segue to-a

    在a中定义(.h)- (IBAction)unwindToA:(UIStoryboardSegue *)unwindSegue;

            (.m)- (IBAction)unwindToA:(UIStoryboardSegue *)unwindSegue

               {

                   UIViewController* sourceViewController = unwindSegue.sourceViewController; //sourceViewController:b

                   if ([sourceViewController isKindOfClass:[B class]])

                   {

                       ......//事先可以sourceViewController(即b)中声明可公开访问的属性,以便在此可访问到

                   }

               }

     在main.storyboard中,将b中navigation bar上的按钮 control-drag到exit上(视图控制器界面上下方最右边绿色图标  ),在弹出的shortcut菜单上选中刚才设置的unwindToA,之后在运行时点击此按钮,即可返回

     p.s.在http://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-to-use-them中有更详细描述

3。在mac中抓图:

     Launchpad-其他-抓图,完成后,文件是保存为tiff格式,双击此文件,在预览中把文件导出为png,就可当图像使用了

4.静态显示UITableView内容:

     a.TableView - Content:Static Cells

     b.Table View Cell - Style:Basic

     c.注释方法-numberOfSectionsInTableView:, tableView:numberOfRowsInSection:, tableView:cellForRowAtIndexPath:. 

5.返回类型:instancetype and id

    凡是通过alloc,init,new方式返回对象时,返回类型要用instancetype(而不是用id)

    e.g.

    @interface MyObject

    +(instancetype)myFactoryMethod;

    @end

    @implementation MyObject

    +(instancetype)myFactoryMethod {

        return [[[self class] alloc] init] ;  //要用self,这样才可以在其子类中也适用

    }

    @end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值