2011-12-07 5 views
0

개체를 만든 MyTextBoxCreator. 나는 많은 텍스트 박스를 동적으로 만들 필요가있다. 메서드에 프레임을 전달할 수 있기를 원합니다. 내가 CGRect에 대한 myRect와 텍스트 필드를 만들려고 할 때개체 메서드는 CGRect를 전달하는 것을 좋아하지 않습니다.

.h file 
-(UITextField *) standardTextField: (CGRect *) myRec; 


.m file 
-(UITextField *) standardTextField: (CGRect *) myRect 
{ 
    UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 30)]; 

    UITextField *myTextField = [[UITextField alloc] initWithFrame:myRect]; 
    myTextField.font = [UIFont fontWithName:textFieldFont size:textFieldFontSize]; 
    myTextField.borderStyle = UITextBorderStyleLine; 
    myTextField.backgroundColor = [UIColor whiteColor]; 
    myTextField.textColor = [UIColor textFieldTextColor]; 
    myTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
    myTextField.layer.borderColor = [[UIColor textfieldBorderColor]CGColor]; 
    myTextField.layer.borderWidth = 1.0f; 
    myTextField.leftView = paddingView; 
    myTextField.leftViewMode = UITextFieldViewModeAlways; 
    myTextField.clearButtonMode = UITextFieldViewModeWhileEditing; 

    return myTextField; 
} 

, 난 오류 얻을 :

Sending 'CGRect *' (aka 'struct CGRect *') to parameter of incompatible type 'CGRect" (aka "struct CGRect') 

내가 CGRect 전달에 무슨 잘못 이해하지를 ...

답변

7

CGRect에 포인터를 전달하지 말고 그냥 구조 자체를 전달하십시오. 그것은 구조 아닌 실제 객체 있다는

-(UITextField *) standardTextField: (CGRect) myRect; 

참고. 당신이, 당신이 할 수있는 역 참조 구조체에 대한 포인터를 전달해야하는 경우

는 비록 :

... 
-(UITextField *) standardTextField: (CGRect *) myRect { 
CGRect rectStruct = *myRect; 
... 
UITextField *myTextField = [[UITextField alloc] initWithFrame:rectStruct]; 
... 
+0

: 그렇지 않으면, 당신은 CGRect 포인터를 참조를 해제해야합니다. 이 경우 영업 담당자는이를 참조 해제해야합니다. 당신은 답안에 이것에 관한 한 줄을 추가해야합니다. – Macmade

+0

@Macmade 팁을 추가해 주셔서 감사합니다. –

+0

아니, 그것을 포인터를 전달하지 않아도 그냥 습관의 힘으로 않았다. 감사. – Padin215

2

initWithFrame:CGRect합니다. CGRect* 매개 변수를 전달 중입니다.

서명을 CGRect으로 변경하는 것이 더 간단 할 것 같습니다. 어쩌면 포인터가 일부 모호한 이유로 필요

UITextField *myTextField = [[UITextField alloc] initWithFrame:*myRect]; 
관련 문제