2015-06-08 30 views
0

我有一個UIImageView,我將其放置在界面構建器中,並設置爲我創建的自定義類SASImageView。然而,當視圖被加載時,我想做一些設置,因此我已經將代碼放入awakFromNib,但是,這似乎並未被調用。iOS中xibs的設置代碼。 -awakFromNb:

- (void)awakeFromNib { 
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapGesture:)]; 
    tap.numberOfTapsRequired = 1; 
    [self addGestureRecognizer:tap]; 
} 

I set the the custom class to be SASImageView which is a subclass of UIImageView

如何我會做一些設置這一觀點在代碼中,從界面生成器的加載後?

謝謝。

+0

嘗試把它放在'initWithCoder:'方法中 – rebello95

+0

輝煌,謝謝! –

+0

沒問題。如果您願意接受它,我會將其作爲答案與更具體的信息一起發佈,以供將來參考。 – rebello95

回答

1

這是你可以輕易地在initWithCoder:方法,因爲你是從XIB文件中加載:

-(id)initWithCoder:(NSCoder *)aDecoder { 

    self = [super initWithCoder:aDecoder]; 
    if (self) { 

     //Add customizations here 
     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapGesture:)]; 
     tap.numberOfTapsRequired = 1; 
     [self addGestureRecognizer:tap]; 
    } 
    return self; 
} 

旁註:設置numberOfTapsRequired1是不必要的,因爲這是默認的。