私はUISegmentedcontrolと2つのオプションを持つUINavigationcontrolを持っています。 2つのオプションは異なるUIViewコントローラーにプッシュします。ユーザが2番目のオプションを押すと、UISegmentControlはまだそこにありますが、ユーザが最初のオプションを再び押すとUISegmentControlは消えます。そこにはどんなコードが必要ですか?UISavmentedcontrol with UINavigationcontrol - UISCが消える
CoreDataMenuAppDelegate.h:
#import <UIKit/UIKit.h>
@interface CoreDataMenuAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UINavigationController *navigationController;
UINavigationController *navigationController2;
UITabBarController *tabBarController;
IBOutlet UISegmentedControl *myMent;
}
-(IBAction)segmentAction:(id)sender;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController2;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
CoreDataMenuAppDelegate.m:私が試した
#import "CoreDataMenuAppDelegate.h"
#import "RootViewController.h"
#import "Step3.h"
#import "Step6.h"
@implementation CoreDataMenuAppDelegate
@synthesize window;
@synthesize navigationController;
@synthesize navigationController2;
@synthesize tabBarController;
-(void)viewDidLoad
{
[myMent addTarget:self action:@selector(segmentAction:)
forControlEvents:UIControlEventValueChanged];
myMent.selectedSegmentIndex = 0 ;
}
- (IBAction) segmentAction:(id)sender
UISegmentedControl* segCtl = sender ;
if([segCtl selectedSegmentIndex] == 0)
{
[navigationController2 popToRootViewControllerAnimated:NO];
//What to put here?
}
if([segCtl selectedSegmentIndex] == 1)
{
NSLog(@"hi this is second segment");
Step6 *step6 = [[[Step6 alloc] initWithNibName:@"Step6" bundle:nil] autorelease];
[self.navigationController2 pushViewController:step6 animated:NO];
step6.navigationItem.titleView = segCtl;
}
}
- (void)dealloc {
[navigationController release];
[navigationController2 release];
[tabBarController release];
[window release];
[super dealloc];
}
:
Step3 *step3 = [[[Step3 alloc] initWithNibName:@"Step3"
step3.navigationItem.titleView = segCtl;
が、結果なしで
。UISegmentControlは、私が2番目のセグメントを押すとUIViewControllerに行くときを示しますが、最初のセグメントに戻ると消えます。
誰でも?
敬具、 xqtr
オーケー、私はそれを使用しようとすると、segmentedcontrolは最初から消えます。私が使用します。
Step3.h:
#import <UIKit/UIKit.h>
@interface Step3 : UIViewController {
UISegmentedControl * segmentedControl;
}
@property (nonatomic, retain) IBOutlet UISegmentedControl * segmentedControl;
@end
Step3.m:
#import "Step3.h"
@implementation Step3
@synthesize segmentedControl;
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationItem.titleView = self.segmentedControl;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[super dealloc];
}
@end
私は正確にstep3.h/Mとstep6.h /メートルで同じコードを使用し
が、今あなたのスニペットを試してみたところで、Segmentedcontrolは既に開始ビュー(ステップ3)で消えています。
提案がありますか? :)
こんにちはビルドゥドニーとあなたの返信をありがとう!まず第一に、私はかなり私が客観的に新しいことを言って始めます.c。だから私は試行錯誤の方法で学ぶことを試みている;)この小さなコードスニペットよりも何かがあるのだろうか?私はそれを実装しようとしたが、私が得るすべての警告は、 'UIViewController'が '-viewWillAppear'に応答しない可能性があります。ありがとうございました – xqtr
更新、申し訳ありません。単一のBOOLパラメータ –
これに対処する方法のヒントを教えてください。私は間違ったことをしましたか? – xqtr