私は UITableViewRowAction を使用しています。私の要件は、テーブルセルの左スワイプで 2 を表示することUITableViewRowAction button
です。を実装することでそれを達成できます-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath;
。これがそのコードです
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with Button 1");
}];
button.backgroundColor = [UIColor greenColor]; //arbitrary color
UITableViewRowAction *button2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with Button2!");
}];
button2.backgroundColor = [UIColor redColor]; //arbitrary color
return @[button, button2];
}
button
現在、との背景として任意の色を使用していbutton2
ます。
しかし、私の要件は、色の代わりに背景画像を持つことです。ここで与えられた答えを調べ、追加して試して実装しました
button.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"icon_ab_delete.png"]];
それ以外の
button.backgroundColor = [UIColor greenColor];
プロジェクトにicon_ab_delete.pngを保存しています。しかし、アプリを実行すると、何もない白い背景が表示されます。このようなもの:
削除用と思われる編集後のボタンには何も表示されず、ハンドラー内で実行しようとしているイベントをまだキャプチャできるため、存在します。
背景画像を正しく設定しているかどうかを知りたいですか、それとも私が達成しようとしていることを行う他の方法がありますか?
前もって感謝します!