irc*_*rco 11 iphone cocoa-touch objective-c
我刚刚开始使用iphone开发我有一个Tabbed应用程序,我想以模态方式显示一个登录形式,所以我在这里看了Apple Dev 并在我的一个视图控制器中执行了这个操作我将一个按钮连接到以下操作:
#import "LoginForm.h"
...
-(IBAction)showLogin{
LoginForm *lf = [[LoginForm alloc]initWithNibName:@"LoginForm" bundle:nil];
lf.delegate = self;
lf.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:lf animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
当我构建时,我得到"请求成员'委托'的东西不是结构或联合"如果我摆脱第二行,它建立但按下按钮什么都不做.
我在这里错过了什么?
Art*_*pie 20
听起来你还没有声明delegate
LoginForm 的成员.您需要添加代码,以便在LoginForm完成时让UIViewController实例以模态方式呈现LoginForm.以下是如何声明自己的委托:
在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
Run Code Online (Sandbox Code Playgroud)
在LoginForm.m中:
@implementation
@synthesize delegate;
//... the rest of LoginForm's implementation ...
@end
Run Code Online (Sandbox Code Playgroud)
然后在呈现LoginForm的UIViewController实例中(让我们称之为MyViewController):
在MyViewController.h中:
@interface MyViewController : UIViewController <LoginFormDelegate>
@end
Run Code Online (Sandbox Code Playgroud)
在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];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22205 次 |
最近记录: |