この質問をするのはこれで 2 回目ですが、もう少し経験を積んだと感じています。
3 つのタブを持つ iPhone アプリがあり、デリゲートには tabBarController があり、各タブの画面に表示される 3 つのビューはそれぞれ「FirstViewController」、「SecondViewController」、「ThirdViewController」によって制御されます。
2 番目と 3 番目のビューはすべて並べ替えられています。
ここに私の質問があります。最初のタブには、最初のビュー コントローラーのそれぞれの IBOutlet ボタンとメソッドにすべて接続されている 20 個の UIButton があります。現時点では、各メソッドが画面上のすべての情報を非表示にするだけなので、理論的にはテキストボックスなどの情報を押されたときに再表示できますが、IB では非常に面倒です。
基本的に、各ボタンを押すと、独自の .xib ファイルを持つ新しい画面/ビューが表示され、すべての情報を入れることができる戻るボタン (別の UIButton) を押すと現在の画面が破棄され、元に戻ります。 tabA の元のビューに。
これはどのように行われますか?
独自の.xibが付属するUIViewクラスである新しいクラスを作成しようとしました。次に、メソッドの 1 つで、基本的に .xib を使用して新しいビューをセットアップし、それをサブビューとして追加する 3 行のコードを設定します。これは正常に機能し、新しい画面が前面に表示されましたが、この特定のサブビューを削除して元のビューに戻すことができませんでした。
助けてくれてありがとう。
#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
もちろん、独自の .xib ファイルを持つ E87view と呼ばれる新しい .h と .m があります。
- (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;
}