当前模态视图控制器 [英] present modal view controller

查看:117
本文介绍了当前模态视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用iphone开发
我有一个Tabbed应用程序,我想显示一个日志模式
所以我看这里 Apple Dev ,我的视图控制器
我连接一个按钮到以下操作:

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 'delegate' in something not a structure or union" If I get rid of the second line, it builds but pressing the button does nothing.

我在这里缺少什么?

推荐答案

听起来你还没有为LoginForm声明一个委托成员。你需要添加一些代码,让LoginVormController实例在LoginForm完成时模块化地呈现LoginForm。以下是如何声明自己的代理:

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:

在LoginForm.h中:

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

在LoginForm.m中:

In LoginForm.m:

@implementation

@synthesize delegate;

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

@end

然后在提供LoginForm的UIViewController实例中(我们称之为MyViewController):

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

在MyViewController.h中:

In MyViewController.h:

@interface MyViewController : UIViewController <LoginFormDelegate>

@end

在MyViewController.m中:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆