zoukankan      html  css  js  c++  java
  • ObjecticeC之方法、消息和选择器

      在第一篇Car的方法中加入一个类方法:

    + (NSString *) motto
    {
    return(@"Ford Prefects are Mostly Harmless");
    }
    #import <UIKit/UIKit.h>
    #import "Car.h"

    //统一定义颜色和button风格
    #define COOKBOOK_PURPLE_COLOR [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]
    #define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease]

    //定义TestBedViewController控制器
    @interface TestBedViewController : UIViewController
    @end

    //实现控制器
    @implementation TestBedViewController
    //定义函数
    - (void) action: (id) sender
    {
    // Calling a class method
    NSLog(@"%@", [Car motto]);//调用类函数
    }

    - (void) viewDidLoad
    {
    self.navigationController.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;
    self.navigationItem.rightBarButtonItem = BARBUTTON(@"Action", @selector(action:));//设定右边导航栏的按钮的标题和事件
    //此处@selector表示选择器
    }
    @end



  • 相关阅读:
    2019.8.6原型链与继承
    2019.8.2闭包,作用域
    2019.8.1正则二
    2019.7.31正则
    2019.7.29二维数组
    2019.7.28关于数组和循环的八道题
    2019.7.27数组api
    DOM
    JavaScript数组5种去重方法
    JavaScript面向对象
  • 原文地址:https://www.cnblogs.com/foxmin/p/2413093.html
Copyright © 2011-2022 走看看