zoukankan      html  css  js  c++  java
  • Creating Your First Mac AppReviewing the Code 审查代码

    Reviewing the Code

    If you have trouble getting your app to work correctly, compare your code with the listings shown at the end of this chapter and review your action and outlet connections.

    如果你的应用程序运行不正确,重新对照本章结尾处的代码列表,审查你的动作(action)和接口(outlet)连接是否正确。

    Code and Compiler Warnings

    代码 和编译器警告(Warnings)

    Your code should compile without any warnings. If you do receive warnings, it’s recommended that you treat them as likely to be errors. Because Objective-C is a flexible language, sometimes the most you get from the compiler is a warning.

    你的代码编译应该不会出现任何警告。如果出现了警告,我们推荐你像对待错误(errors)一样对待它们。因为Objective-C 是一种灵活的语言(flexible language), 有时候你从编译器得到最多的就是一条警告。

    Code Listings

    This section provides listings for the interface and implementation files of the AppDelegate and Track classes. These listings don’t show comments and other method implementations that are provided by the Xcode template.

    本节提供AppDelegate 和 Track 类的 接口(interface)和实现文件(implementation files)代码。 这些代码不包括注释 和 由Xcode模板提供的其它实现方法。

    The Interface File: AppDelegate.h

    接口文件:AppDelegate.h

    #import <Cocoa/Cocoa.h>
     
    @class Track;
     
    @interface AppDelegate : NSObject <NSApplicationDelegate>
     
    @property (assign) IBOutlet NSWindow *window;
    @property (weak) IBOutlet NSTextField *textField;
    @property (weak) IBOutlet NSSlider *slider;
    @property (strong) Track *track;
     
    - (IBAction)mute:(id)sender;
    - (IBAction)takeFloatValueForVolumeFrom:(id)sender;
    - (void)updateUserInterface;
     
    @end

    The Implementation File: AppDelegate.m

    实现文件:AppDelegate.m

    #import "AppDelegate.h"
    #import "Track.h"
     
    @implementation AppDelegate
     
    @synthesize textField = _textField;
    @synthesize slider = _slider;
     
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        Track *aTrack = [[Track alloc] init];
        [self setTrack:aTrack];
        [self updateUserInterface];
    }
     
    - (IBAction)mute:(id)sender {
        [self.track setVolume:0.0];
        [self updateUserInterface];
    }
     
    - (IBAction)takeFloatValueForVolumeFrom:(id)sender {
        float newValue = [sender floatValue];
        [self.track setVolume:newValue];
        [self updateUserInterface];
    }
     
    - (void)updateUserInterface {
        float volume = [self.track volume];
        [self.textField setFloatValue:volume];
        [self.slider setFloatValue:volume];
    }
     
    @end

    The Interface File: Track.h

    #import <Foundation/Foundation.h>
     
    @interface Track : NSObject
    @property (assign) float volume;
     
    @end

    The Implementation File: Track.m

    #import "Track.h"
     
    @implementation Track
     
    @end
  • 相关阅读:
    Rhino 是一个完全使用Java语言编写的开源JavaScript实现。Rhino通常用于在Java程序中,为最终用户提供脚本化能力。它被作为J2SE 6上的默认Java脚本化引擎。
    VS的快捷键F12改成和ECLIPSE一样用ctrl+点击下载线
    到底要不要拆分函数
    “DllRegisterServer的调用失败”问题解决办法(转)
    select into的缺点
    win8 下脚本安装IIS
    快速打开IIS的方法
    windows下硬盘的逻辑结构
    sql server 2005/2008R2 报“红叉”错,即“不允许所请求的注册表访问权”的错误
    rundll32.exe的相关使用语句
  • 原文地址:https://www.cnblogs.com/patientAndPersist/p/3114117.html
Copyright © 2011-2022 走看看