【发布时间】:2011-12-28 19:46:01
【问题描述】:
我的代码在“IBAction”中按下按钮时进行计算,并将结果以字符串的形式作为“UIAlertView”中的“消息”返回。
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 值,该按钮就可以工作。
- (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];
}
【问题讨论】:
标签: iphone objective-c ios call