`
zcw_java
  • 浏览: 305752 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

何时用self引用会加1,[UIImage imageNamed]使用

 
阅读更多
代码粘的多了点,看着清楚一点
SetupAccountViewController.h文件,声明m_comBoxView,线程不安全,retain(self调用引用+1)
#import <UIKit/UIKit.h>
#import "ComBoxView.h"

@interface SetupAccountViewController : UIViewController
{
    ComBoxView *m_comBoxView;
}
@property (retain,nonatomic) ComBoxView *m_comBoxView;
@end


接下来看看m文件
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSMutableArray* array=[NSMutableArray arrayWithObjects:@"btn_img_listBox", @"btn_img_bolg_background", @"btn_img_listBox", @"btn_img_bolg_background", @"btn_img_listBox", @"btn_img_bolg_background", nil];

    //114 view宽,150view tableview+btn高度
    CGRect frame = CGRectMake(180, 46, 114, 150);


    //注意为什么新alloc一个ComBoxView呢,直接调用self.m_comBoxView是没问题的,重新alloc是为了今后有跟子线程交互时更安全,而且保证self.m_comBoxView引用级数为1,不会发生+2+3的情况
    ComBoxView *comBoxView = [[ComBoxView alloc] initWithFrame:frame];
    comBoxView.m_downListDataSource = array;
    self.m_comBoxView = comBoxView;
    //tab默认背景黑
    m_comBoxView.backgroundColor = [UIColor clearColor];
    [m_comBoxView setImgLeftMark:[array objectAtIndex:0]];
    [comBoxView release];
    
    
    self.title = kViewtitle;
    [self.view addSubview:m_comBoxView];
}

self.m_comBoxView = comBoxView;
这一句比较重要,就是说只有self调用赋值,这个时候引用技术才会+1
m_comBoxView.backgroundColor = [UIColor clearColor];改成
self.m_comBoxView.backgroundColor = [UIColor clearColor];作用相同,也不会影响引用计数,因为这里是调用属性。


下面这个还没有遇到过,但是有朋友说,所以记录一下!大家都注意
myImage = [UIImage imageNamed:@"icon.png"];
这种方法在application bundle的顶层文件夹寻找由供应的名字的图象 。 如果找到图片,装载到iPhone系统缓存图象。那意味图片是(理论上)放在内存里作为cache的。
所以使用小图或者少量图是可以的,大量图则该选用
NSString *path = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"png"];
myImage = [UIImage imageWithContentsOfFile:path];

不过这种方法要注意了,如果有高清图,也就是@2x的,就不能自动获取到了,自己把握吧,做ui可以用imageNamed,要处理的大图就别这样加载了
分享到:
评论

相关推荐

    ios-Clock for iOS (秒针两种旋转样式).zip

    [self setClockBackgroundImage:[UIImage imageNamed:@"xxx"].CGImage]; [self setSecHandImage:[UIImage imageNamed:@"xxx"].CGImage]; [self setMinHandImage:[UIImage imageNamed:@"xxx"].CGImage]; [self ...

    IOS点赞效果按钮源代码下载

    CatZanButton *zanBtn=[[CatZanButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50) zanImage:[UIImage imageNamed:@"Zan"] unZanImage:[UIImage imageNamed:@"UnZan"]]; [zanBtn setCenter:self.view.center]; ...

    SDK1.6.2 demo.zip

    UIImage *thumbImage = [UIImage imageNamed:@"res1thumb.png"]; [WXApiResponseHandler respImageData:imageData MessageExt:nil Action:nil ThumbImage:thumbImage]; [self ...

    ios-图片拖动更换位置.zip

    imageview上面加长按及滑动手势来重置imageView的位置 ..._imagesUrlArr=[@[@"http://chenggua.com/imagesUrl/20151204/201512042214246086.png",[UIImage imageNamed:@"22.jpg"],[UIImage imageNamed:@"33.jpg"],@...

    ios开发UIImage category实现添加水印(图片和文字)

    UIImage *imageWatermarkedImage = [originalImage imageWithImageWatermark:[UIImage imageNamed:@"logo"] offset:CGPointMake(originalImage.size.width - 50, originalImage.size.height - 50)]; ``` 4. **...

    iOS 各种动画

    imageView.image = [UIImage imageNamed:@"twitter background.png"]; [self.view addSubview:imageView]; //Twitter style splash SKSplashIcon *twitterSplashIcon = [[SKSplashIcon alloc] initWithImage:...

    ios-iOS随机数字键盘,可设背景图等.zip

    XTYRandomKeyboard *keyBoad = [[XTYRandomKeyboard alloc] initWithTitleColor:[UIColor blackColor] backGroundImage:[UIImage imageNamed:@"bg.jpg"]]; [keyBoad setInputView:textField]; [self.view ...

    BannerLoop:横幅循环---ios的无限自动滚动循环效果

    UIImage *im1=[UIImage imageNamed:@"1.jpg"]; UIImage *im2=[UIImage imageNamed:@"2.jpg"]; UIImage *im3=[UIImage imageNamed:@"3.jpg"]; BannerLoopView *loopView = [[BannerLoopView alloc]initWithFrame:...

    侧边栏菜单控制器

    NSArray *imageList = @[[UIImage imageNamed:@"menuChat.png"], [UIImage imageNamed:@"menuUsers.png"], [UIImage imageNamed:@"menuMap.png"], [UIImage imageNamed:@"menuClose.png"]]; sideBar = [...

    02-通过代码创建按钮

    // 1.创建按钮 UIButton *btn = [[UIButton alloc] init];... UIImage *normal = [UIImage imageNamed:@"btn_01"]; // 4.2设置普通状态下的背景图片 [btn setBackgroundImage:normal forState:UIControlStateNormal];

    ios-包装了一个富文本类.zip

    att_str = [SHAttributedString attributedEmailStringWithString:att_str insertImage:[UIImage imageNamed:@"compose_emoticonbutton_background_highlighted@2x"] orEmailNameString:@"邮箱"]; //计算size ...

    uibutton切换

    [button setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"2"] forState:UIControlStateHighlighted]; [button addTarget:self action:@selector...

    (OC)TabbarViewController

    vc1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"页面1" image:[UIImage imageNamed:@"tabBarItem1"] selectedImage:[UIImage imageNamed:@"tabBarItem1_selected"]]; vc2.tabBarItem = [[UITabBarItem ...

    KXMenu 十分好用的弹出菜单

    image:[UIImage imageNamed:@"action_icon"] target:self action:@selector(feedBack:)], UIButton * btn = sender; [KxMenu showMenuInView:self.view fromRect:btn.frame menuItems:menuItems]; } - (void)...

    iPhone SDK Examples

    [UIImage imageNamed:@"myImage1.png"], [UIImage imageNamed:@"myImage2.png"], [UIImage imageNamed:@"myImage3.png"], [UIImage imageNamed:@"myImage4.gif"], nil]; UIImageView *myAnimatedImageView = [...

    ios-项目内语言切换.zip

    4.在pch文件里增加宏定义: 文字 KLOCALIZED_String(STR) [[InternationalControl bundle] localizedStringForKey:STR value:nil table:@"Localizable"] 图片 KLOCALIZED_UIImageName(NAME) [UIImage imageNamed:[...

    PicsLikeControl:一种自定义按钮(用户可以通过简单的甩动自定义按钮的功能)

    UIImage *image1 = [UIImage imageNamed:@"main-library-button"]; NSArray *images = @[image0, image1]; 用图像初始化这个控件 PicsLikeControl *picControl = [[PicsLikeControl alloc] initWithFrame:...

    CricleScrollerView:基于ScrollerView进行封装的控件,实现ScrollerView无缝循环滚动

    CricleScrollerView 概述 基于ScrollerView进行封装的控件,...UIImageView *imageView1 = [[UIImageView alloc ] initWithImage: [UIImage imageNamed: @" image1 " ]]; imageView1.frame = CGRectMake( 0 , 0 , self

    DFT的matlab源代码-opencvLib:使用opencv实现对图片明水印、暗水印、信息存储像素、傅里叶转换等

    DFT的matlab源代码 opencvLib 包含opencv的静态库 OpenCVLibz.framework是真机release、 OpenCVLibm.framework是模拟器release、 OpenCVLib.framework是合并真机和模拟器release ...imageNamed:image

    仿网易自动循环广告,也可手动滑动

    imageView image [UIImage imageNamed:[NSString stringWithFormat:@&quot;MQLADPlaceholderPic%d&quot; i+1]]; [viewsArray addObject:imageView]; } self adView [[CycleADScrollView alloc] initWithFrame:...

Global site tag (gtag.js) - Google Analytics