教育目的で、小さな銀行タイプのアプリを作成しています。
すべてのトランザクションは Core Data エンティティとして保存され、Magical Record ヘルパー メソッドを使用してフェッチおよびソートされます。トランザクションは、配列UITableView
によって供給されるに表示されます。fetchedObjects
私はそのように使用できるようにしたいeditActionsForRowAtIndexPath
:
最初のアクションは別のアクションに続きuiviewController
、2 番目と 3 番目のアクションは a に続きますUIPopoverPresentationController
。4 番目のボタンは、トランザクションを削除します。
編集
ボタンを作成するコードは次のとおりです。
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
//Obviously, if this returns no, the edit option won't even populate
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
//Nothing gets called here if you invoke `tableView:editActionsForRowAtIndexPath:` according to Apple docs so just leave this method blank
}
-(NSArray *)myArray:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *delete = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
// Delete code here
}];
UITableViewRowAction *changeAmt = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Amt" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
// popover amount change code
}];
changeAmt.backgroundColor = [UIColor colorWithRed:0.022 green:0.541 blue:0.001 alpha:1.00];
UITableViewRowAction *changeAcct = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Acct" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
// popover account change code
}];
changeAcct.backgroundColor = [UIColor colorWithRed:1.000 green:0.492 blue:0.000 alpha:1.00];
UITableViewRowAction *viewTrans = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"View" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
// Push to view
}];
viewTrans.backgroundColor = [UIColor colorWithRed:0.002 green:0.342 blue:0.710 alpha:1.00];
return @[delete, changeAmt,changeAcct,viewTrans]; //array with the buttons delete, changeAmt, changeAcct, viewTrans
}
これが私の質問です:
どのボタンがどのセグエをトリガーするかを知るにはどうすればよいですか? 接続方法がわかりません。
これは、私のprepareForSegue
. 私の混乱の 1 つのポイントは、??? によって示されます。の引数でsourceRect
:
else if ([[segue identifier] isEqualToString:@"AmountPopSegue"])
{
UIViewController *controller = segue.destinationViewController;
controller.popoverPresentationController.delegate = self;
controller.preferredContentSize = CGSizeMake(320, 186);
UIPopoverPresentationController *thisPPC = controller.popoverPresentationController;
thisNavController = (UINavigationController *)segue.destinationViewController;
AmountChangePopVC *acVC = (AmountChangePopVC *)thisNavController.topViewController;
acVC.delegate = self;
thisPPC.sourceRect = ???;
}
すべての洞察に感謝します。Swift が大流行する前にこのプロジェクトを開始したので、Objective C で書いています。