我在.h文件中有以下代码:
@interface ComposeViewController : UIViewController {
id delegate;
IBOutlet UITextField *notificationTitle;
}
@property (nonatomic, assign) id delegate;
- (IBAction)done:(id)sender;
- (void)scheduleAlert;
@end
并且在.m文件- (void)scheduleAlert {
// open an alert with just an OK button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:(@"Hi") delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
上
我想将NSString *notificationTitle
的内容放在*alert
的消息支持上。如果我使用该代码,它会崩溃- (void)scheduleAlert {
// open an alert with just an OK button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:(@"%@", notificationTitle)
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
我如何将*notificationTitle
传递给*alert
消息?
提前谢谢你:)
答案 0 :(得分:1)
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
message:notificationTitle
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
或
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
message:[NSString stringWithFormat:@"This is the string: %@", notificationTitle]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
答案 1 :(得分:0)
对于UIText字段,您应该使用其text
属性,如此
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:notificationTitle.text delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];