TableViewへの「編集ボタン」、「追加ボタン」の追加
TableViewを作ったものの、これに新しいテーブルを追加したり、ターブルの位置を変更した時には「追加ボタン」や「編集ボタン」をメニュー上に追加します。
下の図の「1.Editボタン」、「2.追加ボタン」みたいなやつです。
追加方法は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;