开发者

Passing the value of a textfield to a function on CocoaTouch

开发者 https://www.devze.com 2023-02-06 05:18 出处:网络
I have the following code on the .h file: @interface ComposeViewController : UIViewController { iddelegate;

I have the following code on the .h file:

@interface ComposeViewController : UIViewController {
    id  delegate;
    IBOutlet UITextField *notificationTitle;
}
@property (nonatomic, assign) id  delegate;
- (IBAction)done:(id)sender;
- (void)scheduleAlert;
@end
And on the .m file
- (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]; }

I want to put the content of the NSString *notificationTitle on the message propietry of the *alert. If I pass using that code it crashes
- (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];
}
How I may pass the *notificationTitle to *alert message?

Thank you in advance :)


UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" 
                          message:notificationTitle
                          delegate:self 
                          cancelButtonTitle:@"OK" 
                          otherButtonTitles: nil];

or

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" 
                          message:[NSString stringWithFormat:@"This is the string: %@", notificationTitle]
                          delegate:self 
                          cancelButtonTitle:@"OK" 
                          otherButtonTitles: nil];


for UIText field, you should use its text property like this

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:notificationTitle.text delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
0

精彩评论

暂无评论...
验证码 换一张
取 消