假設我有此方法:發送零到CGPoint類型參數
- (void)placeView:(UIView*)theView withCenterIn:(CGPoint)centerPoint;
所以我通過圖和點對TE視圖的中心。
但它恰巧我不需要指定中心,只是視圖。
傳遞「nil」會導致錯誤。
請建議如何跳過通過中心點。
請記住,我需要使用的方法是這樣的:
- (void)placeView:(UIView*)theView withCenterIn:(CGPoint)centerPoint{
if(centerPoint == nil){//and I understand that it's a wrong comparison, as I cannot pass "nil" to CGPoint
//set a random center point
}
else{
//set that view to the specified point
}
}
在此先感謝
所以你建議做出2種不同的方法,對吧? – 2012-08-16 12:35:48
@SavaMazăre對,這種方法在你的實現(沒有不必要的'if')和你的調用者(沒有不必要的'withCenterIn:nil')上都更清晰。 – dasblinkenlight 2012-08-16 12:36:46
我明白,這是有道理的。但是如果我需要指定2個不同的點,例如:placeView:witCenterIn:orOriginAt:並且我正在檢查是否有中心,我與中心一起工作,否則我使用原點工作。我正在考慮傳遞一個CGPoint數組,並檢查索引爲0的對象是否爲零,所以我沒有得到中心 - >我將使用原點(假設實際上是一個包含2個對象的數組,其中一個爲零)。 – 2012-08-16 12:40:31