jjzjj

ios ~ 设置BaseViewcontroller:两种方法(系统、自定义)

阳光下的叶子呵 2023-09-21 原文
  • 首页跳转下一页的时候,push前隐藏底下的tabBar
GWTeamInfoViewController *teamInfoVC = [[GWTeamInfoViewController alloc]initWithTeamId:teamId];
    [teamInfoVC setHidesBottomBarWhenPushed:YES]; // 跳到下一页,隐藏底下的tabBar
    [self.navigationController pushViewController:teamInfoVC animated:YES];
注意:侧滑返回上一页(在基类的viewDidAppear中设置YES可侧滑,在禁止侧滑的VC中的viewDidAppear方法中设置NO),如果tabbar那几个首页VC也是使用的基类VC设置侧滑的话,将他们单独设置interactivePopGestureRecognizer = NO,否则在其页面,侧滑之后,点击不了控件。
#pragma mark 视图已经加入到窗口时

-(void)viewDidAppear:(BOOL)animated{

    NSLog(@"视图已经加入到窗口时");

    // 是否允许右滑返回:YES 启动侧滑,NO 禁止侧滑
    [self.navigationController.interactivePopGestureRecognizer setEnabled:YES];

}

  • 第一种:使用系统的导航栏

正式代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.backgroundColor = [UIColor whiteColor];
    // 设置导航栏下边线(投影)去掉
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    // 设置导航栏背景图片
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.navigationController.navigationBar setTintColor:RGBA(0, 0, 0, 1)];
    // 设置导航栏默认标题的颜色和字体的大小
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:RGBA(0, 0, 0, 1), NSFontAttributeName:[UIFont systemFontOfSize:([UIScreen mainScreen].bounds.size.width / 375)*18 weight:UIFontWeightMedium]};

    /// iOS 13.0 之后的新特性:
    NSDictionary *titleTextAttributes = @{NSForegroundColorAttributeName:RGBA(0, 0, 0, 1), NSFontAttributeName:[UIFont systemFontOfSize:([UIScreen mainScreen].bounds.size.width / 375)*18 weight:UIFontWeightMedium]};
    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
        appearance.backgroundColor = [UIColor whiteColor]; // 导航栏背景颜色
        appearance.titleTextAttributes = titleTextAttributes; // 设置导航栏默认标题的颜色和字体的大小
        appearance.shadowColor = [UIColor clearColor]; // 设置导航栏底部的分割线不显示
        self.navigationController.navigationBar.standardAppearance = appearance;
        self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
        
        
    } else {
        // Fallback on earlier versions
        self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
        [self.navigationController.navigationBar setTitleTextAttributes:titleTextAttributes];
    }
    
    self.navigationController.navigationBarHidden = NO;
    
    // 去掉导航栏上【返回】按钮 后面的文字
    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:backButtonItem];
//    self.navigationController.navigationBar.topItem.title = @"";
    
    UIButton *leftBut = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 23, 16)];
    [leftBut setImage:[UIImage imageNamed:@"back_black_icon"] forState:UIControlStateNormal];
    [leftBut addTarget:self action:@selector(clickBackLastPageAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backBar = [[UIBarButtonItem alloc] initWithCustomView:leftBut];
    self.navigationItem.leftBarButtonItem = backBar;
    
    // self.navigationItem.leftItemsSupplementBackButton = NO; // 设置YES,以达到页面可以左滑的目的(但是会有系统"<")
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self; // 自定义 按钮,并实现右滑返回效果(注意:如果不写“(id)”的话,就需要遵守代理UIGestureRecognizerDelegate)
    self.edgesForExtendedLayout = UIRectEdgeNone; // self.view 的坐标在(0,导航栏高度+状态栏高度)
//    self.navigationController.navigationBar.translucent = NO;
/**
    // 禁止“右滑侧边”返回上一页
    if (self.navigationController.interactivePopGestureRecognizer) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
    */

    /*
    // 替换系统的“<"图标
    [self.navigationController.navigationBar setBackIndicatorImage:[UIImage imageNamed:@"back_black_icon"]];
    [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back_black_icon"]];
    self.navigationItem.backBarButtonItem = backBar;
    */
    /**
    // 在有UIScrollview,并且是左右滑动的时候:以免侧滑失效,进行一下操作:
    // 手势互斥(侧滑返回手势失效后才响应UITableView的滑动手势)
    [self.myScrollView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
*/
    
}

- (void)clickBackLastPageAction {
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)toRootViewController {
    UIViewController *viewController = nil;
    while (viewController.presentationController) {
        // 判断是否为最底层控制器
        if ([viewController isKindOfClass:[LRBaseViewController class]]) {
            viewController = viewController.presentingViewController;
            // self.navigationItem.title = @"";
        } else {
            break;
        }
    }
    if (viewController) {
        [viewController dismissViewControllerAnimated:YES completion:nil];
    }
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    appDelegate.nowViewCTRL = self;
}
隐藏导航栏下边线?:某一个页面中设置导航栏下边线的时候
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    // 在该页面显示:
    self.navigationController.navigationBar.shadowImage = [UIImage imageNamed:@""];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
     // 退出该页面隐藏:
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
}
  • 第二种:使用自定义的导航栏?

(原理:将系统的导航栏隐藏,自定义一个UIView和其上边的按钮,即LeftButton和RightButton等等需要的按钮,和标题)

下面代码部分:

BaseViewController.h
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface BaseViewController : UIViewController
/**
 隐藏导航栏 位置占着,隐藏了view
 */
@property (assign,nonatomic) BOOL hiddenNavigationBar;

/** 添加一个半透明的遮盖层:状态栏和导航栏位置,随着滑动,可以改变其透明度 */
@property (nonatomic, strong) UIView * navigationBack_TranslucentView;

@property (strong,nonatomic) UIView * statusBg;
@property (strong,nonatomic) UIView * navigationBar;

@property (strong,nonatomic) UIView * contentBg;

/**
 带圆角的view,全局用
 */
@property (strong,nonatomic) UIView * circularBackgroundView;

/**
 标题Label
 */
@property (strong,nonatomic) UILabel * titleLabel;

/**
 左侧图片 用于左侧图片+title时的表现
 */
@property (strong,nonatomic) UIImageView * leftImage;

/**
 左侧按钮,在animationType是0时默认是返回按钮
 */
@property (strong,nonatomic) UIButton * leftButton;

/**
 最右面按钮,在animationType是1时默认是返回按钮
 */
@property (strong,nonatomic) UIButton * rightButton;

/**
 下方横线
 */
@property (strong,nonatomic) UIView * naviBarBottomLineView;

/**
导航栏下面如果是圆角,就把这个属性设置成YES
*/
@property (assign,nonatomic) BOOL isRoundTop;

- (void)back;


@end

NS_ASSUME_NONNULL_END

BaseViewController.m
#import "BaseViewController.h"
#import "UIView+Extension.h"

@interface BaseViewController () 
@property (strong,nonatomic) UIView * redBg;
@property (strong,nonatomic) UIView * rightButtonsBg;
@property (strong,nonatomic) UIView * rightButtonsBgLine;

@end 

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = ColorBaseNaviBarBackground;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self; // 右滑返回上一页
    
    /** 添加一个半透明的遮盖层:状态栏和导航栏位置,随着滑动,可以改变其透明度 */
    _navigationBack_TranslucentView = [[UIView alloc] init];
    _navigationBack_TranslucentView.backgroundColor = RGBA(248, 246, 242, 0); // 设置全透明
    self.navigationBack_TranslucentView.hidden = YES; // 默认隐藏,有需要时显示,并改变其透明度
    [self.view addSubview:self.navigationBack_TranslucentView];
    [self.navigationBack_TranslucentView makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.mas_equalTo(k_Height_StatusBar+k_Height_NavContentBar);
    }];

    /**
     // 使用方法:
     self.navigationBack_TranslucentView.hidden = NO;
     self.navigationBack_TranslucentView.backgroundColor = RGBA(248, 246, 242, 0);
     
     // 当UITableView滑动时,逐渐改变其透明度
     - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
         if (scrollView == self.tableView) {
             if (self.tableView.contentOffset.y <= 0) {
                 self.navigationBack_TranslucentView.backgroundColor = RGBA(248, 246, 242, 0);
             } else {
                 self.navigationBack_TranslucentView.backgroundColor = RGBA(248, 246, 242, self.tableView.contentOffset.y * 0.01);
             }
         }
     }
     */

    //navigationbar上面部分
    _statusBg = [[UIView alloc]init];
    _statusBg.backgroundColor = ColorBaseNaviBarBackground;
    [self.view addSubview:_statusBg];
    [_statusBg mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.equalTo(self.view);
        make.height.equalTo(@(k_Height_StatusBar));
    }];
    
    //上面背景
    _navigationBar = [[UIView alloc] init];
    _navigationBar.userInteractionEnabled = YES;
    self.navigationBar.backgroundColor = ColorBaseNaviBarBackground;
    [self.view addSubview:self.navigationBar];
    
    [_navigationBar mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.statusBg.mas_bottom);
        make.left.right.equalTo(self.view);
        make.height.equalTo(@(k_Height_NavContentBar));
    }];
    
    
    _circularBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, k_Height_NavBar, SCREEN_WIDTH, SCREEN_HEIGHT-k_Height_NavBar)];
    _circularBackgroundView.backgroundColor = [UIColor whiteColor];
    _circularBackgroundView.hidden = YES;
    UIBezierPath *cornerRadiusPath = [UIBezierPath bezierPathWithRoundedRect:_circularBackgroundView.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(30, 30)];

    CAShapeLayer *cornerRadiusLayer = [ [CAShapeLayer alloc ] init];
    cornerRadiusLayer.frame = _circularBackgroundView.bounds;
    cornerRadiusLayer.path = cornerRadiusPath.CGPath;
    _circularBackgroundView.layer.mask = cornerRadiusLayer;
    [self.view addSubview:self.circularBackgroundView];
    

    
    //左侧图标
    _leftImage = [[UIImageView alloc]init];
    //_leftImage.contentMode = UIViewContentModeScaleAspectFill;
    [self.navigationBar addSubview:_leftImage];
    
    //push时隐藏
    _leftImage.hidden = YES;
    
    [_leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.navigationBar).offset(6);
        make.centerY.equalTo(self.navigationBar);
        make.width.height.equalTo(@32);
        //        make.left.top.bottom.equalTo(self.navigationBar);
        //        make.width.equalTo(self.leftImage.mas_height);
    }];
    
    //左侧返回
    _leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_leftButton setImage:[UIImage imageNamed:@"back_icon"] forState:UIControlStateNormal];
    [self.navigationBar addSubview:_leftButton];
    
    //非push时隐藏
    _leftButton.hidden = NO;
    _leftButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [_leftButton addTarget:self action:@selector(clickLeftButton) forControlEvents:UIControlEventTouchUpInside];
    
    [_leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.navigationBar);
        make.centerY.equalTo(self.navigationBar);
        make.width.offset(APP_transverse_Scale(41));
        make.height.equalTo(self.navigationBar);
    }];
    _naviBarBottomLineView = [[UIView alloc]init];
    _naviBarBottomLineView.backgroundColor = RGB(230, 230, 230);
    _naviBarBottomLineView.hidden =YES;
    [self.navigationBar addSubview:_naviBarBottomLineView];
    [_naviBarBottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.navigationBar);
        make.centerX.equalTo(self.navigationBar);
        make.bottom.equalTo(self.navigationBar);
        make.height.offset(APP_transverse_Scale(1));
    }];
    //左侧title
    _titleLabel = [[UILabel alloc]init];
    _titleLabel.textColor = ColorBaseNaviBarTitle;
    _titleLabel.font = FontNaviBarTitle;
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.text = @"";
    [self.navigationBar addSubview:_titleLabel];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(self.navigationBar);
        make.centerY.equalTo(self.navigationBar);
        make.left.mas_equalTo(self.navigationBar.mas_left).offset(APP_transverse_Scale(44));
        make.right.mas_equalTo(self.navigationBar.mas_right).offset(APP_transverse_Scale(-44));
    }];
    
    //右上按钮背景
    _rightButtonsBg = [[UIView alloc]init];
    _rightButtonsBg.backgroundColor = RGBA(0, 0, 0, .5);
    _rightButtonsBg.layer.cornerRadius = 16;
    _rightButtonsBg.layer.masksToBounds = YES;
    [self.navigationBar addSubview:_rightButtonsBg];
    
    _rightButtonsBg.backgroundColor = [UIColor clearColor];
    
    [_rightButtonsBg mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.navigationBar).offset(-APP_transverse_Scale(10));
        make.top.equalTo(self.navigationBar).offset(APP_transverse_Scale(6));
        make.bottom.equalTo(self.navigationBar).offset(-APP_transverse_Scale(6));
        make.width.offset(APP_transverse_Scale(78));
    }];
    
    //背景上的线
    _rightButtonsBgLine = [[UIView alloc]init];
    _rightButtonsBgLine.backgroundColor = [UIColor whiteColor];
    [self.rightButtonsBg addSubview:_rightButtonsBgLine];
    
    _rightButtonsBgLine.hidden = YES;
    
    [self.rightButtonsBgLine mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.rightButtonsBg).offset(APP_transverse_Scale(4));
        make.bottom.equalTo(self.rightButtonsBg).offset(-APP_transverse_Scale(4));
        make.width.equalTo(@1);
        make.centerX.equalTo(self.rightButtonsBg);
    }]; 
    
    //最右侧按钮
    _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_rightButton setImage:[UIImage imageNamed:@"icon_nav_close"] forState:UIControlStateNormal];
    [_rightButtonsBg addSubview:_rightButton];
    [_rightButton addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    _rightButton.hidden = NO;
    [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.rightButtonsBg);
        make.top.bottom.equalTo(self.rightButtonsBg);
        make.width.equalTo(self.rightButton.mas_height);
    }];
    
    
    self.contentBg = [[UIView alloc]init];
    self.contentBg.layer.cornerRadius = 10;
    self.contentBg.layer.masksToBounds = YES;
    self.contentBg.backgroundColor = ColorBaseNaviBarBackground;
    [self.view addSubview:self.contentBg];
    
    [self.contentBg mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.navigationBar.mas_bottom);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.mas_bottomLayoutGuide).offset(APP_transverse_Scale(20));
    }];
    
    self.isRoundTop = self.isRoundTop;
    self.statusBg.backgroundColor = RGBA(221, 203, 177, 1);
    self.navigationBar.backgroundColor = RGBA(221, 203, 177, 1);
    self.titleLabel.textColor = RGBA(0, 0, 0, 1);
    
}
#pragma mark - setter/getter

- (void)setIsRoundTop:(BOOL)isRoundTop{
    
    _isRoundTop = isRoundTop;
    self.redBg.hidden = self.contentBg.hidden = isRoundTop == NO;
}
- (void)setHiddenNavigationBar:(BOOL)hiddenNavigationBar{
    
    _hiddenNavigationBar = hiddenNavigationBar;
    self.statusBg.hidden = self.navigationBar.hidden = hiddenNavigationBar;
}
#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:YES animated:animated];
} 
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    
    // NSLog(@"视图已经加入到窗口时");
    
    // 是否允许右滑返回:YES 启动侧滑,NO 禁止侧滑
    [self.navigationController.interactivePopGestureRecognizer setEnabled:YES];
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];

}
- (void)clickLeftButton{
    [self back];
}

- (void)back;{
    [self.navigationController popViewControllerAnimated:YES]; 
}

- (void)rightBtnClick {
    
}



/** 横屏设置: */
#pragma mark //屏幕旋转
/// 决定当前界面是否开启自动转屏,如果返回NO,后面两个方法也不会被调用,只是会支持默认的方向
//- (BOOL)shouldAutorotate {
//    return NO; // NO 下面的方法不执行,YES 执行下面的方法 (supportedInterfaceOrientations)
//}
//
//// 2.返回支持的旋转方向
//// 设置当前界面支持的所有方向,所以返回值是UIInterfaceOrientationMask,更加方便的表达支持多方向旋转的情况。
//- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
//    return UIInterfaceOrientationMaskPortrait; // 只支持这一个方向(正常的方向)
//}
//
//// 3.返回进入界面默认显示方向
//-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
//    return UIInterfaceOrientationPortrait;
//}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

有关ios ~ 设置BaseViewcontroller:两种方法(系统、自定义)的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  3. ruby - 使用 RubyZip 生成 ZIP 文件时设置压缩级别 - 2

    我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看ruby​​zip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d

  4. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  5. ruby - Facter::Util::Uptime:Module 的未定义方法 get_uptime (NoMethodError) - 2

    我正在尝试设置一个puppet节点,但ruby​​gems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由ruby​​gems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby

  6. ruby-openid:执行发现时未设置@socket - 2

    我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass

  7. Ruby 方法() 方法 - 2

    我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby​​-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco

  8. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  9. ruby - Highline 询问方法不会使用同一行 - 2

    设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案

  10. ruby-on-rails - 如何使用 instance_variable_set 正确设置实例变量? - 2

    我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击

随机推荐