0
내 코드는 "IBAction"의 버튼을 눌렀을 때 계산을 수행하고 결과를 "UIAlertView"의 "message"문자열로 반환합니다.다른 방법으로 한 방법에서 계산 된 값으로 변수를 호출하는 방법은 무엇입니까?
else{
NSString *str = [[NSString alloc] initWithFormat:@"You require an average GPA of at least %.2f to achieve your Goal of %@", gpagoal, (NSString *)[myPickerDelegate.myGoal objectAtIndex: [myPicker selectedRowInComponent:0]]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Nothing is Impossible"
message:str
delegate:self
cancelButtonTitle:@"Good Luck"
otherButtonTitles:@"Tweet",nil];
//show alert
[alert show];
[alert release];
NSLog(@"All Valid");
}
나는 계산의 "IBAction"방법에서 "gpagoal"값을 가져 오는 방법에 문제가 있습니다.
아래 코드는 다른 방법에서 gpagoal 값을 포트 할 수있는 경우 작동하는 tweeting 용 독립 실행 형 버튼 코드입니다.
- (IBAction)sendEasyTweet:(id)sender {
// Set up the built-in twitter composition view controller.
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
// i have problem trying to pull the result "gpagoal" from the calculation's "IBAction" method as i dunno how to pull out variable from a method to another method.
NSString *str2 = [[NSString alloc] initWithFormat:@"I need an average GPA of at least %.2f this semester to achieve my Goal of %@", gpagoal, (NSString *)[myPickerDelegate.myGoal objectAtIndex: [myPicker selectedRowInComponent:0]]];
// Set the initial tweet text. See the framework for additional properties that can be set.
[tweetViewController setInitialText:str2];
// Create the completion handler block.
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
//NSString *output;
switch (result) {
case TWTweetComposeViewControllerResultCancelled:
// The cancel button was tapped.
//output = @"Tweet cancelled.";
NSLog(@"Tweet cancelled");
break;
case TWTweetComposeViewControllerResultDone:
// The tweet was sent.
//output = @"Tweet done.";
NSLog(@"Tweet done");
break;
default:
break;
}
// Dismiss the tweet composition view controller.
[self dismissModalViewControllerAnimated:YES];
}];
// Present the tweet composition view controller modally.
[self presentModalViewController:tweetViewController animated:YES];
}
나는 실제로 이전에 View Controller의 인터페이스에 "double gpagoal"을 추가하는 것을 시도했다. 그런 다음 경고 메시지가 표시됩니다. 'gpagoal'에 대한 로컬 선언은 인스턴스 변수를 숨 깁니다. 당신의 대답을 읽은 후에, 나는 변수를 초기화하지 않았기 때문에 내가 경고를받는 이유가 있다고 생각한다. 그래서 어떻게 그것을 초기화하고 변수를 업데이 트해야합니까? 감사. – at0m87
'viewDidLoad'에서'pgagoal = 1.0;'을 설정하십시오. 컨트롤러가'pgagoal'이 변경된 뷰나 모델로부터 정보를 얻을 때마다,'gpagoal'을 새로운 값으로 설정하십시오. – Mundi
괜찮은 viewdidload, 무엇을 입력해야합니까? GPAMainViewController * gpagoal = 0; ? – at0m87