问题描述
在我做一个客户端服务器程序,其中我想从一个视图切换到另一个,但我收到一个错误clientserverprogram view.mplz help clientserverprogram view.h
#import< UIKit / UIKit.h>
@class secondview;
@interface clientserverprogramViewController:UIViewController {
IBOutlet UITextField * name;
IBOutlet UITextView * filepath;
IBOutlet UIButton * print;
IBOutlet UIButton * settings;
IBOutlet UIButton * cancel;
IBOutlet UILabel * display;
IBOutlet secondview * secondview;
}
- (IBAction)print;
- (IBAction)设置;
- (IBAction)cancel;
@property(nonatomic,retain)IBOutlet UITextField * name;
@property(nonatomic,retain)IBOutlet UITextView * filepath;
@property(nonatomic,retain)IBOutlet UILabel * display;
@end
clientserverprogram view.m
#importclientserverprogramViewController.h
#importsecondview.h
@implementation clientserverprogramViewController
@synthesize名称,文件路径,显示;
- (IBAction)print {
NSString * str = name.text;
[display setText:str];
}
- (IBAction)设置{
[self presentModalViewController:secondview animated:YES];
错误:'secondview'之前的预期表达式
}
- (IBAction)cancel {
exit(0);
}
- (void)dealloc {
[super dealloc];
}
@end
secondview.h
#import< UIKit / UIKit.h>
@interface secondview:UIViewController {
IBOutlet UIView * view;
IBOutlet UIButton * back;
}
- (IBAction)back;
@end
secondview.m
#importsecondview.h
@implementation secondview
- (IBAction)back {
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
- (void)dealloc {
[super dealloc];
}
@end
[self presentModalViewController:secondview animated:YES];
错误:'secondview'之前的预期表达式
代码行负责呈现模态ViewController。在你的情况下,你只有一个看法。所以你可以为第二个视图创建一个控制器:
SecondViewController * secondController = [[SecondViewController alloc] initWithNibName:@ secondViewbundle:[NSBundle mainBundle]];
[self presentModalViewController:secondController animated:YES];
或者您可以使用插座从nib文件加载第二个视图,您可以将其作为子视图添加到当前视图控制器视图:
[self.view addSubView:secondview];
更新
你的代码SecondView是你的控制器不是视图,但你试图呈现一个没有初始化的控制器。我还注意到,你有一个插座,你的视图在SecondView,当你创建一个新的UIViewController子类,你可以检查创建一个.xib文件的选项。
希望有帮助,
i m making a client server program in which i want to switch from one view to another but i am getting an error in "clientserverprogram view.m" plz help
"clientserverprogram view.h"
#import <UIKit/UIKit.h>
@class secondview;
@interface clientserverprogramViewController : UIViewController {
IBOutlet UITextField *name;
IBOutlet UITextView *filepath;
IBOutlet UIButton *print;
IBOutlet UIButton *settings;
IBOutlet UIButton *cancel;
IBOutlet UILabel *display;
IBOutlet secondview *secondview;
}
-(IBAction) print;
-(IBAction) settings;
-(IBAction) cancel;
@property (nonatomic , retain) IBOutlet UITextField *name;
@property (nonatomic , retain) IBOutlet UITextView *filepath;
@property (nonatomic , retain) IBOutlet UILabel *display;
@end
"clientserverprogram view.m"
#import "clientserverprogramViewController.h"
#import "secondview.h"
@implementation clientserverprogramViewController
@synthesize name ,filepath,display ;
-(IBAction) print {
NSString *str = name.text;
[display setText : str];
}
-(IBAction) settings {
[self presentModalViewController: secondview animated: YES ];
"" error: expected expression before 'secondview'""
}
-(IBAction) cancel {
exit(0);
}
- (void)dealloc {
[super dealloc];
}
@end
"secondview.h"
#import <UIKit/UIKit.h>
@interface secondview : UIViewController {
IBOutlet UIView *view;
IBOutlet UIButton *back;
}
-(IBAction) back;
@end
""secondview.m""
#import "secondview.h"
@implementation secondview
-(IBAction) back {
[self.parentViewController dismissModalViewControllerAnimated: YES];
}
- (void)dealloc {
[super dealloc];
}
@end
[self presentModalViewController: secondview animated: YES ];
"" error: expected expression before 'secondview'""
This line of code is responsible to present modal ViewController. In your case you only had a view. So either you create a controller for the second view like that:
SecondViewController *secondController=[[SecondViewController alloc] initWithNibName:@"secondView" bundle:[NSBundle mainBundle]];
[self presentModalViewController:secondController animated: YES ];
or you can load you second view from nib file using outlet and you can add it as subview to your current view controller view:
[self.view addSubView:secondview];
Update
As I can see on your code SecondView is your controller not the view, but you are try to present a controller that is not initialized. I also noticed that you have an outlet for your view on SecondView, when you create a new sub class of UIViewController you can check the option that creates a .xib file as well.
Hope that helps,
这篇关于切换视图在iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!