2015-01-12 6 views
-1

이 함수에서 UIWebView를 호출하려고하는데 오류가 발생합니다. 이 오류를 어떻게 해결할 수 있습니까? 함수에서 변수를 호출 할 수있는 방법이 있습니까? 그 이유는 내 webViewDidFinishLoad가 UIWebView에서 키가 변경되기 때문입니다. 그 아래에 UIImage를로드하려고합니다. 당신의 변수가 함수 내에서 설정되어 있기 때문에신속한 기능 오류

, 다른 기능에서 액세스 할 수 없습니다

func webViewDidFinishLoad (jobDescView : UIWebView){ 
     // Change the height dynamically of the UIWebView to match the html content 
     var jobDescViewFrame: CGRect = jobDescView.frame 
     jobDescViewFrame.size.height = 1 
     jobDescView.frame = jobDescViewFrame 
     var fittingSize: CGSize = (jobDescView.sizeThatFits(CGSizeZero)) 
     jobDescViewFrame.size = fittingSize 
     // webViewFrame.size.width = 276; Making sure that the webView doesn't get wider than 276 px 
     jobDescView.frame = jobDescViewFrame 
     var jobDescViewHeight = jobDescView.frame.size.height 

    } 

    func bar2View (bar2View: UIImageView){ 
     var jobDescViewHeight = jobDescView.frame.size.height -->>ERROR unresolved identifier 'jobDescView' 
    } 

답변

2

이 변수 범위와 관련이있다. 의미가 클래스 변수 다음 jobDescViewFrame = jobDescView.frame

class MyClass : OptionalSuperClass, OptionalProtocol1 { 
var jobDescViewHeight:CGFloat! 

func webViewDidFinished(jobDescView:UIWebView){ 
    jobDescViewFrame = jobDescView.frame 
} 

func bar2View (bar2View: UIImageView){ 
    jobDescViewHeight = jobDescView.frame.size.height ' 
} 
+0

좋아 같은

설정 var에 jobDescViewFrame. 그래서 프로젝트의 시작 부분이나 그 함수 안에있는 클래스에 변수를 설정합니까? 그렇다면 클래스 변수를 어떻게 설정 하시겠습니까? – Tom

+0

업데이트 됨. 작동하는지 알려주세요. =) – ericgu

+0

괜찮 았던 것.이 클래스는 선언되지 않은 TypeSuperClass, jobDescViewFrame 및 jobDescView를 말하면서 오류가 발생했다. – Tom