ios开发小技巧及经验积累

1、       调用系统相册、相机发现是英文的系统相簿界面后标题显示“photos”,但是手机语言已经设置显示中文,

             解决办法:在info.plist设置解决问题          

          info.plist里面添加Localized resources can be mixed YES

        表示是否允许应用程序获取框架库内语言。

 

2、调整状态栏的颜色 : 重写视图控制器的方法

       

    - (UIStatusBarStyle)preferredStatusBarStyle

    {

       returnUIStatusBarStyleLightContent;

    }

    注:该方法只在没有导航控制器的情况下使用,如在右但航控制器的情况下,可先隐藏导航条,然后再使用该方法。

 

3、使用UIActionSheet进行调用UIPickerController时出现的问题

   Warning:Attempt to present <UIImagePickerController:0x7c0ae400> on <CAGUCreateContactViewController:0x7bf61a00> which is already presenting (null)

 

    问题分析:I think this is because in iOS 8, alert views and action sheets are actually presented view controllers (UIAlertController). So, if you're presenting a new view controller in response to an action from the UIAlertView, it's being presented while the UIAlertController is being dismissed. I worked around this by delaying the presentation of the UIImagePickerControlleruntil the next iteration of the runloop

        

      解决办法:

I simply moved my code that reacts on Action Sheet selection from: 

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
{
// my code
} (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
{
// my code
}

into:

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;  // after animation
{
// my code
} (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;  // after animation
{
// my code
}

This way app is guarantied that code will be executed AFTER UIActionSheet animation finishes.

Since UIAlertView has similar delegate method:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;  // after animation
{
// my code
} (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;  // after animation
{
// my code
}
<span style="color:#cc0000">4、修改UIImage尺寸</span>
   UIImage类本身没有提供更改其尺寸的方法,故应该对其添加一个方法UIImage类本身没有提供更改其尺寸的方法,故应该对其添加一个方法
    -(UIImage *)TransformtoSize:(CGSize)Newsize -(UIImage *)TransformtoSize:(CGSize)Newsize

{

     // 创建一个bitmap的context

     UIGraphicsBeginImageContext(Newsize);

     // 绘制改变大小的图片

    [self drawInRect:CGRectMake(00, Newsize.width, Newsize.height)];

     // 从当前context中创建一个改变大小后的图片

     UIImage *TransformedImg=UIGraphicsGetImageFromCurrentImageContext();

     // 使当前的context出堆栈

     UIGraphicsEndImageContext();

     // 返回新的改变大小后的图片

     return TransformedImg;

}

5、获取button所在的cell

 /**********获取button所在的cell***********************/

    UITableViewCell * cell = (UITableViewCell *)[[button superview] superview];

    NSIndexPath * indexPath = [_tableView indexPathForCell:cell];

 /**********获取button所在的cell***********************/

6、数组在遍历中如要进行数组元素的操作,则要备份数组

7、tableView上方出现空白的问题
 

UIScrollView(包括其子类,比如UITableView):会自动在顶部和底部预留一些空白(因为滚动经过半透明导航条或者tabbar下面,需要能隐约看到的效果),是否预留空白可以由UIViewController的

automaticallyAdjustsScrollViewInsets的这个属性控制(默认YES,表示预留空白)。

上面这些只要你用iOS开发,就能发现。

一个控制器中,出现UIScrollView(包括其子类),必须是第一个添加到控制器的视图上才会预留空白,这里的第一个是相对于所有的子视图,不仅仅是其他UIScrollView(包括其子类)。

 self.automaticallyAdjustsScrollViewInsets=NO; 就不会出现空白

并且tableView的style要设为默认,不能为style:UITableViewStyleGrouped

 

 

 

最后 由于春运快到了,给大家安利一个抢火车票的小程序心到抢票,微信扫码关注点击立即抢票即可

个人亲测效率很高,大家也可以加他们官方微信  xdticket  咨询。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值