ツヨシのブログ

技術的な事とか日常の事とか徒然なるままに

スポンサーリンク

TableViewに編集ボタンと追加ボタンを加える

スポンサーリンク

TableViewへの「編集ボタン」、「追加ボタン」の追加

TableViewを作ったものの、これに新しいテーブルを追加したり、ターブルの位置を変更した時には「追加ボタン」や「編集ボタン」をメニュー上に追加します。

下の図の「1.Editボタン」、「2.追加ボタン」みたいなやつです。

f:id:ginga0118:20140106224357p:plain

追加方法はUIBarButtonItemクラスにより追加を行います。

参照ソース

 //「追加ボタン」をナビゲーションに追加
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]init];
addButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveEdit:)];
self.navigationItem.rightBarButtonItem = addButton;


//編集ボタンを左側に追加
self.navigationItem.leftBarButtonItem = self.editButtonItem;

おまけ

ちなみに、「3.アクセサリタイプ」は「accessoryType 」プロパティにより設定します。

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;