macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

image

セルの画像を返します

解説

セルの画像を返します。画像タイプセルでなかったり、画像がなければnilを返します。

返り値

( NSImage * )

画像

引数

フレームワーク

ApplicationKit

クラス

NSCell

Instance Methods

使用可能

10.0

参照

- setImage:

例文

/* @interface MyObject : NSObject
{
    IBOutlet id but;//ボタン
    IBOutlet id image;//画像
    IBOutlet id info;//テキストフィールド
    IBOutlet id bCell1;//ボタンセル
    IBOutlet id bCell2;//ボタンセル
}
- (IBAction)myAction:(id)sender;
*/
#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{

    //開けるファイル拡張子の配列
    NSArray      *imgTypes    = [ NSArray arrayWithObject : @"tiff" ];
    //OpenPanelを作る
    NSOpenPanel  *opImage       = [ NSOpenPanel openPanel ];
    //Imageを作る
    NSImage      *img;

    //OpenPanelの結果のボタン番号
    int		  opRet;
     
        //OpenPanelでファイル選択   
    opRet = [ opImage runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
                                     file : @"Pictures" //どのどのファイルを選択しておくか
                                    types : imgTypes ];//選べるファイルタイプ

    if ( opRet == NSOKButton ) {  // OPENPanelのボタンがOKなら
        //NSImageを作ってファイルから読み込む
        img = [ [ NSImage alloc ] 
                          initWithContentsOfFile: [ opImage filename ] ];


[bCell1 setImage:img];
[bCell2 setImage:[bCell1 image]];

}
}

@end