何时用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
- (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];}