UISegmentedControl を使用して 3 つのビューを切り替えたいのですが、行き詰まっています。
私はストーリーボードとARCを使用していますが、これまでのところ:
セグメント化されたコントロールを VC にドラッグし、セグメント化されたコントロールに接続する IBOutlet と IBAction を作成しました。
.h ファイルは次のようになります。
#import <UIKit/UIKit.h>
@interface SCViewController : UIViewController
@property (strong, nonatomic) IBOutlet UISegmentedControl *segment;
- (IBAction)changeSeg:(id)sender;
@end
次に、.m ファイルで:
#import "SCViewController.h"
@interface SCViewController ()
@end
@implementation SCViewController
@synthesize segment;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidUnload {
[self setSegment:nil];
[super viewDidUnload];
}
- (IBAction)changeSeg:(id)sender {
if(segment.selectedSegmentIndex == 0){
NSLog(@"page one pressed");
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"segmentView1"]];
}
if(segment.selectedSegmentIndex == 1){
NSLog(@"page two pressed");
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"segmentView2"]];
}
}
@end
コンソールには NSLog メッセージが表示されますが、ビューは切り替えられません (ストーリーボードに vc segmentView1 と segmentView2 が存在します)。
多分私はこれで間違ったアプローチを使用していますか?
私が実現したいのは、iDaft2 アプリのような機能です。そこには 2 つまたは 3 つのページがあり、それらを簡単に切り替えることができます。
ご協力いただきありがとうございます!