//tableviewXib
@interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableview;
@property(nonatomic,strong)NSString *string;
@property(nonatomic,strong)NSDictionary *dict;
- (void)viewDidLoad {
[super viewDidLoad];
_tableview.delegate =self;
_tableview.dataSource = self;
_dict = @{@"百度":@"https://www.baidu.com",@"腾讯":@"https://www.qq.com",@"新浪":@"https://www.sina.com"};
[self.view addSubview:_tableview];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[_dict allKeys] count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if(cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = [_dict allKeys][indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
_string = [_dict allValues][indexPath.row];
[self performSegueWithIdentifier:@"xian" sender:nil];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"xian"]){
id send = segue.destinationViewController;
[send setValue: _string forKey:@"string"];
}
}
@interface Viewsen : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UIButton *button;
@property(nonatomic,strong)NSString *string;
@property(nonatomic,strong)NSDictionary *dict;
@end
- (void)viewDidLoad {
[super viewDidLoad];
[_button setTitle:@"返回" forState:UIControlStateNormal];
UIWebView *web=[[UIWebView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
NSURL *url=[NSURL URLWithString:_string];
[web loadRequest:[NSURLRequest requestWithURL:url]];
[_button bringSubviewToFront:web];
[self.view addSubview:web];
[self.view addSubview:web];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//ScollView
//对图片进行缩放:首先设置ScrollView,注意ScrollView只是容器,滚动或缩放的都是其中的控件当内部的控件比scrollView大才可以进行缩放或拖拽的。
//设置ScrollView的contentSize
//遵守协议
//设置代理对象
//设置将要缩放的控件(协议方法)
//设置最大/最小缩放比例
//缩放捏合的手势需按下option
- (void)viewDidLoad {
[super viewDidLoad];
_viewOfScroll.delegate=self;//设置代理对象
_viewOfScroll.contentSize=_image.frame.size;//设置ScrollView的滚动的大小
_viewOfScroll.maximumZoomScale=3;//设置放大的倍数
_viewOfScroll.minimumZoomScale=0.4;//设置缩小的倍数
}
//设置将要被缩放的控件
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return _image;
}
//拖拽结束回调方法
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
NSLog(@"拖拽了");
}
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *textFeild;
- (IBAction)chuanzhi:(id)sender;
- (IBAction)chuanzhi:(id)sender {
NSUserDefaults *userDefault=[NSUserDefaults standardUserDefaults];
[userDefault setValue:_textFeild.text forKey:@"lable"];
[userDefault synchronize];
}
@interface twoPage : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *labelInTwo;
@implementation twoPage
-(void)viewDidLoad{
[super viewDidLoad];
NSUserDefaults *userDefault=[NSUserDefaults standardUserDefaults];
_labelInTwo.text=[userDefault valueForKey:@"lable"];
}
来源:oschina
链接:https://my.oschina.net/u/2501648/blog/532187