学会Segmented Control点击切换视图
故事版:
<br/ ><br/ >
要注意的是,这里有两个view,一个是被隐藏的,我放在了同一个位置
功能描述:
1 2 3 4 5 6 7 8 9 10 11
| st=>start: 开始 e=>end: 结束 op=>operation: 选择一个segment s1=>operation: 个人信息segment s2=>operation: 学校信息segment r1=>operation: 个人信息页面 r2=>operation: 学校信息页面 cond=>condition: 判断选择哪一个segment st->op->cond cond(yes)->s1->r1->e cond(no)->s2->r2->e
|
代码:
把第三个View Controller换成自己写的类showLabelViewController(因为开始是做点击按钮显示名字事件的,所以取了这个名字)
<br/ >
- showLabelViewController.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
# import <UIKit/UIKit.h>
@interface showLabelViewController : UIViewController
- (IBAction)actionShowName:(id)sender;
- (IBAction)actionSelectPage:(id)sender;
@property (strong, nonatomic) IBOutlet UIView *viewUserPage;
@property (strong, nonatomic) IBOutlet UIView *viewSchoolPage;
@property (strong, nonatomic) IBOutlet UISegmentedControl *segmentControl;
@property (strong, nonatomic) IBOutlet UILabel *lblShow;
@property (strong, nonatomic) NSString *name; @end
|
<br/ >
- showLabelViewController.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
# import "showLabelViewController.h"
@interface showLabelViewController ()
@end
@implementation showLabelViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { } return self; }
- (void)viewDidLoad { [super viewDidLoad]; self.name = @"Lotty周小鱼"; }
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; }
- (IBAction)actionShowName:(id)sender { self.lblShow.text = self.name; }
- (IBAction)actionSelectPage:(id)sender { switch (self.segmentControl.selectedSegmentIndex) { case 0: self.viewSchoolPage.hidden = true; self.viewUserPage.hidden = false; break; case 1: self.viewSchoolPage.hidden = false; self.viewUserPage.hidden = true; break; default: break; } }
@end
|
结果
最后结果就是点击segment切换不同的View
有什么问题都可以在博文后面留言,或者微博上私信我。
博主是 iOS 妹子一枚。
希望大家一起进步。
我的微博:Lotty周小鱼