iOS 頁面跳轉傳值,屬性傳值,代理傳值,代碼塊傳值,單例傳值,通知傳值

来源:http://www.cnblogs.com/qianLL/archive/2016/03/16/5281611.html
-Advertisement-
Play Games

有時候我們在頁面跳轉的時候回傳遞相應的參數,如,你想把在第一個頁面的文本框里的內容顯示在第二個文本框中,或者你又想把第二個文本框中的內容改變之後到第一個頁面的文本框中,所有,這個時候我們就要用到頁面跳轉傳值 屬性傳值是正向傳值,只可以從前面一個頁面傳遞到第二個頁面,不可以從第二個頁面傳遞到第一個頁面


有時候我們在頁面跳轉的時候回傳遞相應的參數,如,你想把在第一個頁面的文本框里的內容顯示在第二個文本框中,或者你又想把第二個文本框中的內容改變之後到第一個頁面的文本框中,所有,這個時候我們就要用到頁面跳轉傳值

1.屬性傳值(正向傳值)


 

屬性傳值是正向傳值,只可以從前面一個頁面傳遞到第二個頁面,不可以從第二個頁面傳遞到第一個頁面

2.代理傳值(逆向傳值)


 

代理傳值是逆向傳值

代理傳值步驟

代理傳值
適用於 反向傳值
1.1 創建協議 及協議方法 在反向傳值的頁面(SecondViewController)中
1.2 創建協議類型的屬性 在SecondViewController中創建屬性id<postValueDelegate> delegate
1.3 調用屬性 即delegate
在SecondViewController頁面中 對象傳值的方法中調用
[self.delegate postValue:self.textName.text];

1.4 在第一頁 即顯示修改過信息的頁面
遵循協議 實現協議方法 指定代理對象(即 在頁面傳值參數的方法中為代理賦值)

具體代碼如下

firstViewController.h

#import <UIKit/UIKit.h>
#import "secondViewController.h"
@interface firstViewController : UIViewController<postValueDeletage,UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@end

firstViewController.m

#import "firstViewController.h"

@interface firstViewController ()

@end

@implementation firstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:0.565 green:1.000 blue:0.994 alpha:1.000];
    
    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.delegate=self;
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    [self.view addSubview:self.name1];
    
    
    
    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"點擊" forState:0];
    [self.btn addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];
    
    
    [self.view addSubview:self.btn];
    
    
}

-(void)postValue:(NSString *)str{

    self.name1.text=str;
}

-(void)next{
    secondViewController *second=[[secondViewController alloc]init];
    second.deletage=self;
    second.str=self.name1.text;
    [self presentViewController:second animated:YES completion:nil];
    
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    
    return YES;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.name1 resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

secondViewController.h 第二個頁面

#import <UIKit/UIKit.h>
@protocol postValueDeletage <NSObject>

-(void)postValue:(NSString *)str;

@end
@interface secondViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@property(nonatomic,strong)NSString *str;
@property(nonatomic,assign)id<postValueDeletage> deletage;
@end

secondViewController.m

#import "secondViewController.h"

@interface secondViewController ()

@end

@implementation secondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:1.000 green:0.314 blue:0.659 alpha:1.000];
    
    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    self.name1.text=self.str;
    [self.view addSubview:self.name1];
    self.name1.delegate=self;
    self.name1.text=self.str;
    
    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"上一頁" forState:0];
    [self.btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];
    
    
    [self.view addSubview:self.btn];

}
-(void)back{
    
    [self.deletage postValue:self.name1.text];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.name1 resignFirstResponder];
    
}

AppDelegate.h

#import <UIKit/UIKit.h>
#import "firstViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@end

AppDelegate.m文件 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    firstViewController *first=[[firstViewController alloc]init];
    self.window.rootViewController=first;
    
    
    return YES;
}

3.單例傳值(雙向傳值)


 

首先創建一個單例類

AppStatus.h

#import <Foundation/Foundation.h>

@interface AppStatus : NSObject<NSCopying>
@property(nonatomic,copy)NSString *contextStr;
+(AppStatus *)shareInstance;
@end

AppStatus.m文件

#import "AppStatus.h"

@implementation AppStatus
static AppStatus *appstatus;
//單例方法
+(AppStatus *)shareInstance{
    if (appstatus==nil) {
        appstatus=[[AppStatus alloc]init];
    }
    
    
    return appstatus;
}
//單例方法 初始化
+(instancetype)allocWithZone:(struct _NSZone *)zone{
    if (appstatus==nil) {
        appstatus=[super allocWithZone:zone];
    }
    return appstatus;
}

//單例方法 複製
-(id)copyWithZone:(NSZone *)zone{

    return self;
}
@end

第一個頁面

firstViewController.h

#import <UIKit/UIKit.h>
#import "sceondViewController.h"
#import "AppStatus.h"
@interface firstViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@end

firstViewController.m

#import "firstViewController.h"

@interface firstViewController ()

@end

@implementation firstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:0.565 green:1.000 blue:0.994 alpha:1.000];
    
    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    self.name1.delegate=self;
    [self.view addSubview:self.name1];
    
    
    
    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"下一頁" forState:0];
    [self.btn addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];
    
    
    [self.view addSubview:self.btn];

}

//這個方法是執行多遍的  相當於刷新view

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
      //把contextStr賦值到first中文本框的內容中
    self.name1.text=[AppStatus shareInstance].contextStr;
}
-(void)next{

    sceondViewController *second=[[sceondViewController alloc]init];
    //把first中文本框的內容賦值到contextStr中
    [AppStatus shareInstance].contextStr=self.name1.text;
    NSLog(@"%@",[AppStatus shareInstance].contextStr);
    
    [self presentViewController:second animated:YES completion:nil];
    
    
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.name1 resignFirstResponder];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

第二個頁面sceondViewController.h

#import <UIKit/UIKit.h>
#import "AppStatus.h"
@interface sceondViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@end
#import "sceondViewController.h"

@interface sceondViewController ()

@end

@implementation sceondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:1.000 green:0.416 blue:0.612 alpha:1.000];
    
    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    self.name1.text=[AppStatus shareInstance].contextStr;
    self.name1.delegate=self;
    [self.view addSubview:self.name1];

    
    
    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"上一頁" forState:0];
    [self.btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];
    
    
    [self.view addSubview:self.btn];
    
}
-(void)back{
    
    //把second中的文本框的值賦值給單例類的contextStr
    [AppStatus shareInstance].contextStr=self.name1.text;
    NSLog(@"%@",[AppStatus shareInstance].contextStr);

    [self dismissViewControllerAnimated:YES completion:nil];
    
    
    
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.name1 resignFirstResponder];
}

//這個方法是執行多遍的  相當於刷新view
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //把contextStr賦值到second中文本框的內容中
    self.name1.text=[AppStatus shareInstance].contextStr;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

把根視圖轉到第一個視圖,最後代碼和代理模式的一樣,在AppDelegate的

4.通知傳值(逆向傳值)


 

註意:通知傳值是逆向傳值,只能在第二個頁面創建通知和發送通知,在第一個頁面接收通知,並讀取通知里的信息

第一個頁面

firstViewController.h

#import <UIKit/UIKit.h>
#import "secondViewController.h"
@interface firstViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;

@end

firstViewController.m

#import "firstViewController.h"

@interface firstViewController ()

@end

@implementation firstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:0.565 green:1.000 blue:0.994 alpha:1.000];
    
    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    self.name1.delegate=self;
    [self.view addSubview:self.name1];
    
    
    
    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"點擊" forState:0];
    [self.btn addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];
    
    
    [self.view addSubview:self.btn];
    
    //添加通知
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(ChangeNameNotification:) name:@"order" object:nil];
    
    
}
//通知方法
-(void)ChangeNameNotification:(NSNotification *)notification{
    
    NSDictionary *nameDic=notification.userInfo;
    NSLog(@"%@",nameDic);
    self.name1.text=[nameDic objectForKey:@"key"];
    
    
}
-(void)next{
 
    secondViewController *second=[[secondViewController alloc]init];
    second.str=self.name1.text;
    [self presentViewController:second animated:YES completion:nil];
    

    
}
//移除通知
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"order" object:nil];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if ([textField  isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.name1 resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

第二個頁面secondViewController.h

#import <UIKit/UIKit.h>

@interface secondViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@property(nonatomic,strong)NSString *str;
@end

第二個頁面secondViewController.m

#import "secondViewController.h"

@interface secondViewController ()

@end

@implementation secondViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=[UIColor colorWithRed:1.000 green:0.314 blue:0.659 alpha:1.000];
    
    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    [self.view addSubview:self.name1];
    
    self.name1.text=self.str;
    
    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"上一頁" forState:0];
    [self.btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];
    
    
    [self.view addSubview:self.btn];

}
-(void)back{
    //創建通知
    NSNotification *no=[[NSNotification alloc]initWithName:@"order" object:self userInfo:@{@"key":self.name1.text}];
    //通知中心發送通知
    [[NSNotificationCenter defaultCenter] postNotification:no];
    [self dismissViewControllerAnimated:YES completion:nil];
    
    
    
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.name1 resignFirstResponder];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*

把根視圖轉到第一個視圖,最後代碼和代理模式的一樣,在AppDelegate的

5.代碼塊傳值(逆向傳值)


 

代碼塊傳值步驟

/**

 *  代碼塊傳值 從後往前傳值

 1.聲明代碼塊(secondXXX.h)

 2.聲明一個代碼塊的類型屬性(secondXXX.h)

 3.調用代碼塊(secondXXX.m)

 4.實現代碼塊(FirstXXX.m)

 第一個頁面firstViewController.h和

#import <UIKit/UIKit.h>
#import "secondViewController.h"
@interface firstViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;

@end
#import "firstViewController.h"

@interface firstViewController ()

@end

@implementation firstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor redColor];
    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    self.name1.borderStyle=2;
    self.name1.delegate=self;
    [self.view addSubview:self.name1];
    
    
    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(200, 300, 100, 100)];
    [self.btn setTitle:@"下一頁" forState:0];
    [self.btn addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:self.btn];
}

//-(void)postValue:(NSString *)str{
//
//    self.name1.text=str;
//}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    
    return YES;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.name1 resignFirstResponder];
}
-(void)next{
    secondViewController *second=[[secondViewController alloc]init];
    second.str=self.name1.text;
    
    second.myBlock=^(NSString *info){
    
        self.name1.text=info;
    
    };
//    second.deletage=self;
    [self presentViewController:second animated:YES completion:nil];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

 

第二個頁面 firstViewController.h和firstViewController.m

#import <UIKit/UIKit.h>
typedef void(^postValueBlock)(NSString *info);
//@protocol postValueDeletage <NSObject>
//
//-(void)postValue:(NSString *)str;
//
//@end

/**
 *  代碼塊傳值 從後往前傳值
 1.聲明代碼塊(secondXXX.h)
 2.聲明一個代碼塊的類型屬性(secondXXX.h)
 3.調用代碼塊(secondXXX.m)
 4.實現代碼塊(FirstXXX.m)
 
 */

@interface secondViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@property(nonatomic,copy)NSString *str;
@property(nonatomic,strong)postValueBlock myBlock;
#import "secondViewController.h"

@interface secondViewController ()

@end

@implementation secondViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor=[UIColor grayColor];
    
    
    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    self.name1.borderStyle=2;
    self.name1.text=self.str;
    //    self.name1.backgroundColor=[UIColor ];
    [self.view addSubview:self.name1];
    
    
    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(200, 300, 100, 100)];
    [self.btn setTitle:@"上一頁" forState:0];
    [self.btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:self.btn];


}

-(void)back{
    
    
//    if (self.deletage!=nil) {
//        [self.deletage postValue:self.name1.text];
//
//    }
    
    
    if (self.myBlock) {
        self.myBlock(self.name1.text);
    }

    
    [self dismissViewControllerAnimated:YES completion:nil];

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.name1 resignFirstResponder];
}


-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

把根視圖轉到第一個視圖,最後代碼和代理模式的一樣,在AppDelegate的

本文主要是使用第一個文本框的值傳遞到第二個頁面的文本框中,修改第二個頁面文本框中的內容,同時又顯示到第一個頁面的文本框中,為屬性複製都寫在幾種傳值的裡面(除了單例傳值)


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 說明:用線性漸變創建圖像 語法: <linear-gradient> = linear-gradient([ [ <angle> | to <side-or-corner> ] ,]? <color-stop>[, <color-stop>]+) <side-or-corner> = [left |
  • iOS 4.0+ 使用英文字體 Helvetica Neue,之前的iOS版本降級使用 Helvetica 中文字體設置為華文黑體STHeiTi 預設數字字體是Helvetica Neue 需補充說明,華文黑體並不存在iOS的字體庫中(http://support.apple.com/kb/HT58
  • 也可以基於這一思路測試某個值是不是原生函數或正則表達式: 方法2、在聲明函數時指定適當的函數,這樣第一次調用函數不損失性能,在代碼首次載入時會損失性能 按下按鈕實際顯示的是undefined,並不會顯示Event handled。問題在於沒有保存handler.handleClick的環境,所以th
  • CSS: HTML: JS:
  • 點擊按鈕,自動生成100個li,紅、黃、藍、綠四種顏色的順序顯示出現在頁面中 CSS: HTML: JS:
  • 一,效果圖。 二,工程圖。 三,代碼。 RootViewController.h RootViewController.m
  • 當內容及分類較多時,往往採用頂部標簽式導航欄,例如網易新聞客戶端的頂部分類導航,最近剛好有這樣的應用場景,參考網路上一些demo,實現了這種導航效果,記錄一些要點。 效果圖(由於視頻轉GIF掉幀,滑動和下拉動畫顯得比較生硬,剛發現quickTime可以直接錄製手機視頻,推薦一下,很方便) 其實就是在
  • Android應用檢查版本更新後,在通知欄下載,更新下載進度,下載完成自動安裝,效果圖如下: AndroidManifest文件中的versionCode用來標識版本,在伺服器放一個新版本的apk,versioncode大於當前版本,下麵代碼用來獲取versioncode的值 用當前versionc
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...