当前位置: 首页 > news >正文

外卖网站建设的策划百度浏览器打开

外卖网站建设的策划,百度浏览器打开,网站后台选项卡效果,卧龙区网站制作在这节中可以学习到XCODE中个人偏好和数据归档化两种数据持久方法: (Todo: 数据归档化没有成功,不知道错在什么地方) 数据归档必须将模型数据的头文件实现NSCoding协议,并在模型数据代码文件中实现两个协议方法 #impo…

在这节中可以学习到XCODE中个人偏好和数据归档化两种数据持久方法:

(Todo: 数据归档化没有成功,不知道错在什么地方)
















数据归档必须将模型数据的头文件实现NSCoding协议,并在模型数据代码文件中实现两个协议方法


#import "TXContact.h"


@implementation TXContact


- (id)initWithCoder:(NSCoder *)aDecoder
{
    if(self = [super init]){
        self.name = [aDecoder decodeObjectForKey:@"name"];
        self.phone = [aDecoder decodeObjectForKey:@"phone"];
    }
    return self;
}


- (void)encodeWithCoder:(NSCoder *)encoder
{
    [encoder encodeObject:self.name forKey:@"name"];
    [encoder encodeObject:self.phone forKey:@"phone"];
}


@end

------------------------------

#import "TXLoginViewController.h"
#import "MBProgressHUD+MJ.h"
#import "TXContactViewController.h"


@interface TXLoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *accountView;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
@property (weak, nonatomic) IBOutlet UITextField *pwdView;
- (IBAction)RmbChange:(id)sender;
- (IBAction)AutoChange:(id)sender;
@property (weak, nonatomic) IBOutlet UISwitch *RmbSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *AutoSwitch;
- (IBAction)login;


@end


@implementation TXLoginViewController




- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSLog(@"dddd");
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accountPwdChange) name:UITextFieldTextDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accountPwdChange) name:UITextFieldTextDidChangeNotification object:self.pwdView];
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    BOOL autoSwitch = [defaults boolForKey:@"AutoSwitch"];
    BOOL rmbSwitch = [defaults boolForKey:@"RmbSwitch"];
    NSString *account = [defaults objectForKey:@"account"];
    NSString *pwd = [defaults objectForKey:@"pwd"];
    
    self.AutoSwitch.on = autoSwitch;
    self.RmbSwitch.on = rmbSwitch;
    self.accountView.text = account;
    self.pwdView.text = pwd;
    
    
    if(rmbSwitch){
        self.loginBtn.enabled = YES;
    }
    
    if (autoSwitch) {
        [self login];
    }
}


- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


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


- (void)accountPwdChange
{
    self.loginBtn.enabled = (self.accountView.text.length && self.pwdView.text.length);
}




- (IBAction)RmbChange:(id)sender {
    
    [self.view endEditing:YES];


    if(self.RmbSwitch.isOn == NO){
        self.AutoSwitch.on = NO;
    }
}


- (IBAction)AutoChange:(id)sender{
    [self.view endEditing:YES];
    
    if(self.AutoSwitch.isOn){
        self.RmbSwitch.on = YES;
    }
}


- (IBAction)login {
    if(![self.accountView.text isEqualToString:@"txj"]){
        [MBProgressHUD showError:@"Account is error"];
        return;
    }
    if(![self.pwdView.text isEqualToString:@"123"]){
        [MBProgressHUD showError:@"Password is error"];
        return;
    }
    
    [MBProgressHUD showMessage:@"Loading..."];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [MBProgressHUD hideHUD];
        
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        
        [defaults setBool:self.RmbSwitch.isOn forKey:@"RmbSwitch"];
        [defaults setBool:self.AutoSwitch.isOn forKey:@"AutoSwitch"];
        
        if(self.RmbSwitch.isOn){
            [defaults setObject:self.accountView.text forKey:@"account"];
            [defaults setObject:self.pwdView.text forKey:@"pwd"];
        }else{
            [defaults setObject:nil forKey:@"account"];
            [defaults setObject:nil forKey:@"pwd"];
        }
        
        [defaults synchronize];


        
        [self performSegueWithIdentifier:@"contact" sender:nil];
        
    });
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    TXContactViewController *vc = segue.destinationViewController;
    vc.navigationItem.title = [NSString stringWithFormat:@"%@的通讯录", self.accountView.text];
}
@end


#import "TXContactViewController.h"
#import "TXAddViewController.h"
#import "TXEditViewController.h"
#import "TXContact.h"


#define DATAPATH [[NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"contacts.data"]




@interface TXContactViewController () <UIActionSheetDelegate, TXAddViewControllerDelegate, TXEditViewControllerDelegate>
@property (nonatomic, strong) NSMutableArray *contacts;
- (IBAction)logout:(id)sender;
@end


@implementation TXContactViewController




- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSLog(@"%@--------", DATAPATH);
    
}


- (NSMutableArray *)contacts
{
    if(_contacts == nil)
    {
        _contacts = [NSKeyedUnarchiver unarchiveObjectWithFile:DATAPATH];
        if(_contacts == nil)
        {
            _contacts = [NSMutableArray array];
        }
    }
    return _contacts;
}




#pragma mark - Table view data source




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.contacts.count;
}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"contact";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    /*
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
    }
    */
    
    TXContact *contact = self.contacts[indexPath.row];
    
    cell.textLabel.text = contact.name;
    cell.detailTextLabel.text = contact.phone;
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}


-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(editingStyle == UITableViewCellEditingStyleDelete){
        
        [self.contacts removeObjectAtIndex:indexPath.row];
        
        [self.tableView reloadData];
        
        [NSKeyedArchiver archiveRootObject:self.contacts toFile:DATAPATH];
    }
}




- (IBAction)logout:(id)sender
{
    NSString *title = @"确定要注销吗?";
    NSString *cfm = @"确定";
    NSString *cancel = @"取消";
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:cancel destructiveButtonTitle:cfm otherButtonTitles:nil, nil];
    
    [sheet showInView:self.view];
    
}


- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex != 0) return;
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    id vc = segue.destinationViewController;
    if ([vc isKindOfClass:[TXAddViewController class]]) {
        TXAddViewController *addvc = vc;
        addvc.delegate = self;
    }else if([vc isKindOfClass:[TXEditViewController class]]){
        TXEditViewController *editvc = vc;
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        TXContact *contact = self.contacts[indexPath.row];
        editvc.contact = contact;
        editvc.delegate = self;
    }
}


- (void)addViewAddContact:(TXContact *)contact
{
    [self.contacts addObject:contact];
    
    [self.tableView reloadData];
    
    [NSKeyedArchiver archiveRootObject:self.contacts toFile:DATAPATH];
}


-(void)editViewControllerEditContact:(TXContact *)contact
{
    [self.tableView reloadData];
    
    [NSKeyedArchiver archiveRootObject:self.contacts toFile:DATAPATH];
}


@end

----------------------------

#import "TXAddViewController.h"
#import "TXContact.h"


@interface TXAddViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameView;
@property (weak, nonatomic) IBOutlet UITextField *phoneView;
@property (weak, nonatomic) IBOutlet UIButton *saveBtn;
- (IBAction)save;


@end


@implementation TXAddViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged) name:UITextFieldTextDidChangeNotification object:self.nameView];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged) name:UITextFieldTextDidChangeNotification object:self.phoneView];
}


- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (void)textChanged
{
    self.saveBtn.enabled = (self.nameView.text.length && self.phoneView.text.length);
}


- (IBAction)save {
    [self.navigationController popViewControllerAnimated:YES];
    
    
    if ([self.delegate respondsToSelector:@selector(addViewAddContact:)]) {
        TXContact *contact = [[TXContact alloc] init];
        contact.name = self.nameView.text;
        contact.phone = self.phoneView.text;
        
        [self.delegate addViewAddContact:contact];
    }
    
}
@end


#import "TXEditViewController.h"
#import "TXContact.h"


@interface TXEditViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameView;
@property (weak, nonatomic) IBOutlet UITextField *phoneView;
@property (weak, nonatomic) IBOutlet UIButton *saveBtn;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *editBtn;
- (IBAction)edit:(id)sender;
- (IBAction)save;


@end


@implementation TXEditViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.nameView.text = self.contact.name;
    self.phoneView.text = self.contact.phone;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged) name:UITextFieldTextDidChangeNotification object:self.nameView];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged) name:UITextFieldTextDidChangeNotification object:self.phoneView];
}


- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


-(void)textChanged
{
    self.saveBtn.enabled = (self.nameView.text.length && self.phoneView.text.length);
}




- (IBAction)edit:(id)sender {
    if(!self.nameView.isEnabled)
    {
        self.nameView.enabled = YES;
        self.phoneView.enabled = YES;
        self.saveBtn.enabled = YES;
        self.saveBtn.hidden = NO;
        
        [self.phoneView becomeFirstResponder];
        self.editBtn.title = @"取消";
    }
    else
    {
        self.nameView.text = self.contact.name;
        self.phoneView.text = self.contact.phone;
        
        self.nameView.enabled = NO;
        self.phoneView.enabled = NO;
        self.saveBtn.enabled = NO;
        self.saveBtn.hidden = YES;
        
        [self.view endEditing:YES];
        self.editBtn.title = @"编辑";
    }
}


- (IBAction)save {
    [self.navigationController popViewControllerAnimated:YES];
    
    if([self.delegate respondsToSelector:@selector(editViewControllerEditContact:)])
    {
        self.contact.name = self.nameView.text;
        self.contact.phone = self.phoneView.text;
        
        [self.delegate editViewControllerEditContact:self.contact];
    }
}
@end


多个控制器之间数据传递:

1,顺传:在模板控制器中设置一个模型,然你在源文控制器中通过prepareSega方法取得目标控制器,并将模型传递给目标控制器

2,逆传:可通过代理、通知、Block实现



http://www.lbrq.cn/news/2784511.html

相关文章:

  • 本地合肥网站建设网络营销工具的特点
  • 中国被墙的网站seo推广软件排名
  • 一个人做的网站做什么好北京债务优化公司
  • 网页浏览器网址宁波seo网站
  • 初级web前端工程师证书常用seo站长工具
  • 今日财经重大新闻seo营销技巧培训班
  • 网站的关键词库怎么做seo舆情优化
  • 高端建站服务商百度竞价排名叫什么
  • 网站的上一页怎么做个人网站开发网
  • 厦门网站建设哪家公司好成都有实力的seo团队
  • 国家住房和城乡建设网站辅导机构
  • 学生html美食静态网页代码网站seo优化方案设计
  • 昆明营销型网站建设公司武汉网站开发公司
  • 电商网站怎样做营销推广运营
  • 网站拨测人员是干嘛的河南seo推广
  • 网站做了301怎么查看跳转前网站教育培训机构推荐
  • 网站关键词不稳定企业策划推广公司
  • 带做网站绿标seo搜索引擎优化工资薪酬
  • 建设网站服务器 知乎企业网站推广方案
  • o2o商城网站制作制作网站要花多少钱
  • wordpress 文章索引石家庄关键词优化软件
  • 向国外支付网站开发费找培训机构的网站
  • 可以做仿牌网站郑州百度seo网站优化
  • 青海城乡和住房建设厅网站南京百度
  • 贵州住房和城乡建设部网站首页关键词优化意见
  • 成都专业网站建设价格低班级优化大师手机版下载(免费)
  • 长春网站建站全网推广的方式有哪些
  • 网站的开发工具和运行环境竞价交易规则
  • 真实的做视频网站360网站推广费用
  • 有什么网站接效果图做的常见的网络营销模式
  • “无纸化办公”加速推进,房产证智能识别技术或成行业标配
  • 运维日常工作100条
  • (nice!!!)(LeetCode 每日一题) 1277. 统计全为 1 的正方形子矩阵 (动态规划)
  • mysql-8.0.37-linux-glibc2.12-x86_64安装
  • [Git] 如何拉取 GitHub 仓库的特定子目录
  • JAVA经典面试题:数据库调优