首页 > 代码库 > IOS开发的一些小技巧

IOS开发的一些小技巧

 将图片写入模拟器相册

   UIImageWriteToSavedPhotosAlbum([UIImage imageNamed:@"call"], nil, nil, nil);

 

-------------------------------------------------------------------------------------------------------------------    

    UIView* uiViewBuildingAddress=[[UIViewalloc]initWithFrame:self.view.frame];

    uiViewBuildingAddress.backgroundColor=[UIColorblackColor];

    //父视图不影响子视图背景色

    uiViewBuildingAddress.backgroundColor=[UIColorcolorWithWhite:0

                                                           alpha:0.6];

-------------------------------------------------------------------------------------------------------------------    

 

#pragma mark - 获取view从属的viewController

- (UIViewController*)getViewController

{

    for (UIView* next = [selfsuperview]; next; next = next.superview)

    {

        UIResponder* nextResponder = [next nextResponder];

        if ([nextResponderisKindOfClass:[UIViewControllerclass]])

        {

            

            return (UIViewController*)nextResponder;

        }

    }

    return nil;

}

-------------------------------------------------------------------------------------------------------------------    

避免Block的Retain Cycle

 

            NSURL* nsUrlBindIngHouse=[NSURLURLWithString:[NSStringstringWithFormat:@"%@%@",WEBSERVICE_URL,PersonalCenter_BindIngHouse_HouseList]];

          __block ASIHTTPRequest* asiHTTPRequestBindIngHouse=[ASIHTTPRequestrequestWithURL:nsUrlBindIngHouse];

            __weak ASIHTTPRequest* asiHTTPRequestBindIngHouse2=asiHTTPRequestBindIngHouse;

            

             [asiHTTPRequestBindIngHouse2 setCompletionBlock:^

            {

            }];

            

            [asiHTTPRequestBindIngHouse2 setFailedBlock:^

            {

                NSLog(@"asiHTTPRequestBindIngHouse2.error:%@",asiHTTPRequestBindIngHouse2.error);

            }];

            [asiHTTPRequestBindIngHouse2 startAsynchronous];

 

-------------------------------------------------------------------------------------------------------------------