这是我第二次问这个问题,但我确实觉得有更多的经验,也许这次可以说得更好。
我有一个 iPhone 应用程序,它有 3 个选项卡,委托有一个 tabBarController,每个选项卡的屏幕上显示的 3 个视图分别由“FirstViewController”、“SecondViewController”和“ThirdViewController”控制。
第二个和第三个视图都是排序的。
所以这是我的问题。在第一个选项卡中,我有 20 个 UIButton,它们都连接到第一个视图控制器中各自的 IBOutlet 按钮和方法。目前我的每个方法都只是隐藏屏幕上的所有信息,所以理论上我可以在按下它们时取消隐藏诸如文本框之类的信息,但这在 IB 中变得非常混乱。
本质上,我希望每个按钮在按下时都能显示一个新的屏幕/视图,该屏幕/视图具有自己的 .xib 文件,我可以将所有信息放在包括一个后退按钮(另一个 UIButton)上,当按下该按钮时会破坏当前屏幕并返回到 tabA 的原始视图。
这将如何完成?
我确实尝试过创建一个新类,一个带有自己的 .xib 的 UIView 类。然后我在其中一种方法中设置了 3 行代码,这些代码基本上使用 .xib 设置新视图,然后将其添加为子视图。这工作正常并带来了新的屏幕但是我无法删除这个特定的子视图以返回到原始视图。
感谢您的任何帮助。
#import <UIKit/UIKit.h>
#import "E87view.h"
@interface FirstViewController : UIViewController {
IBOutlet UIButton *E87, *E81, *F20, *E36, *E46, *E90,
*E34, *E39, *E60, *E63, *E64, *E38,
*E65, *F01, *X3, *X5, *Z3, *Z4, *M3, *M5, *backButton;
IBOutlet UILabel *ones, *threes, *fives, *sixs, *sevens, *xs, *zs, *ms;
IBOutlet UITextView *mainText;
}
-(IBAction) E87Pressed;
-(IBAction) E81Pressed;
-(IBAction) F20Pressed;
-(IBAction) E36Pressed;
-(IBAction) E46Pressed;
-(IBAction) E90Pressed;
-(IBAction) E34Pressed;
-(IBAction) E39Pressed;
-(IBAction) E60Pressed;
-(IBAction) E63Pressed;
-(IBAction) E64Pressed;
-(IBAction) E38Pressed;
-(IBAction) E65Pressed;
-(IBAction) F01Pressed;
-(IBAction) X3Pressed;
-(IBAction) X5Pressed;
-(IBAction) Z3Pressed;
-(IBAction) Z4Pressed;
-(IBAction) M3Pressed;
-(IBAction) M5Pressed;
-(IBAction) backButtonPressed;
-(void) hideAll;
-(void) showAll;
@end
还有 .m 文件。显然没有注意 hide 和 show 方法中的隐藏元素。显然我不想使用这种方法,我想推送和弹出新屏幕。保持我的标签
#import "FirstViewController.h"
#import "E87view.h"
@implementation FirstViewController
-(void) hideAll{
E87.hidden = 1;
E81.hidden = 1;
F20.hidden = 1;
E36.hidden = 1;
E46.hidden = 1;
E90.hidden = 1;
E34.hidden = 1;
E39.hidden = 1;
E60.hidden = 1;
E63.hidden = 1;
E64.hidden = 1;
E38.hidden = 1;
E65.hidden = 1;
F01.hidden = 1;
X3.hidden = 1;
X5.hidden = 1;
Z3.hidden = 1;
Z4.hidden = 1;
M3.hidden = 1;
M5.hidden = 1;
ones.hidden = 1;
threes.hidden = 1;
fives.hidden = 1;
sixs.hidden = 1;
sevens.hidden = 1;
xs.hidden = 1;
zs.hidden = 1;
ms.hidden = 1;
mainText.hidden = 1;
backButton.hidden = 0;
}
-(void) showAll{
E87.hidden = 0;
E81.hidden = 0;
F20.hidden = 0;
E36.hidden = 0;
E46.hidden = 0;
E90.hidden = 0;
E34.hidden = 0;
E39.hidden = 0;
E60.hidden = 0;
E63.hidden = 0;
E64.hidden = 0;
E38.hidden = 0;
E65.hidden = 0;
F01.hidden = 0;
X3.hidden = 0;
X5.hidden = 0;
Z3.hidden = 0;
Z4.hidden = 0;
M3.hidden = 0;
M5.hidden = 0;
ones.hidden = 0;
threes.hidden = 0;
fives.hidden = 0;
sixs.hidden = 0;
sevens.hidden = 0;
xs.hidden = 0;
zs.hidden = 0;
ms.hidden = 0;
mainText.hidden = 0;
}
-(IBAction) backButtonPressed{
[self showAll];
backButton.hidden = 1;
//[self.navigationController popToRootViewControllerAnimated:YES];
//for (UIView *subview in [self.view subviews]) {
// [subview removeFromSuperview];
//}
//[self showAll];
}
-(IBAction) E87Pressed{
[self hideAll];
//E87view *e87view = [[E87view alloc] initWithNibName:@"E87view" bundle:[NSBundle mainBundle]];
//[self.navigationController pushViewController:e87view animated:YES];
//[self.view addSubview:e87view.view];
}
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[self showAll];
}
[self showAll];
return self;
}
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
[self showAll];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
//backButton.hidden = 1;
[self showAll];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BackdropService.png"]];
backButton.hidden = 1;
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
当然,我有一个名为 E87view 的新 .h 和 .m 文件,它有自己的 .xib 文件。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the tab bar controller's view to the window and display.
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}