开发者

present modal view controller

开发者 https://www.devze.com 2023-01-08 03:02 出处:网络
I am just getting started with iphone development I have a Tabbed application and I wanted to display a log in form modally

I am just getting started with iphone development I have a Tabbed application and I wanted to display a log in form modally so i looked here Apple Dev and did this inside one of my view controllers I connected a button to the following action:

 #import "LoginForm.h"
...
-(IBAction)showLogin{
LoginForm *lf = [[LoginForm alloc]initWithNibName:@"LoginForm" bundle:nil];
lf.delegate = self;
lf.modalPresentationStyle =  UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:lf animated:YES];
}

when I build I get "request for member 'del开发者_如何学JAVAegate' in something not a structure or union" If I get rid of the second line, it builds but pressing the button does nothing.

What am I missing here?


Sounds like you haven't declared a delegate member for LoginForm. You'll need to add code that lets the UIViewController instance that's presenting LoginForm modally when LoginForm is done. Here's how to declare your own delegate:

In LoginForm.h:

@class LoginForm;

@protocol LoginFormDelegate
- (void)loginFormDidFinish:(LoginForm*)loginForm;
@end

@interface LoginForm {
    // ... all your other members ...
    id<LoginFormDelegate> delegate;
}

// ... all your other methods and properties ...

@property (retain) id<LoginFormDelegate> delegate;

@end

In LoginForm.m:

@implementation

@synthesize delegate;

//... the rest of LoginForm's implementation ...

@end

Then in the UIViewController instance that presents LoginForm (let's call it MyViewController):

In MyViewController.h:

@interface MyViewController : UIViewController <LoginFormDelegate>

@end

In MyViewController.m:

/**
 * LoginFormDelegate implementation
 */
- (void)loginFormDidFinish:(LoginForm*)loginForm {
   // do whatever, then
   // hide the modal view
   [self dismissModalViewControllerAnimated:YES];
   // clean up
   [loginForm release];
}

- (IBAction)showLogin:(id)sender {
    LoginForm *lf = [[LoginForm alloc]initWithNibName:@"LoginForm" bundle:nil];
    lf.delegate = self;
    lf.modalPresentationStyle =  UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:lf animated:YES];
}


It would seem that your LoginForm class derives from UIViewController. The UIViewController class doesn't have a delegate property, hence the compile error you got.

Your problem is probably that the action doesn't get called in the first place. The proper signature for an action is:

- (IBAction)showLogin:(id)sender;

The sender argument is required. Put a breakpoint in your method to make sure it is called.

0

精彩评论

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