選択リストの実装中に、セグエとプロトコルを統合する際にいくつかの問題が発生しています。
私の選択リストに.h私は持っています:
#import <UIKit/UIKit.h>
@protocol SelectionListViewControllerDelegate <NSObject>
@required
- (void)rowChosen:(NSInteger)row;
@end
@interface SelectColor : UITableViewController <NSFetchedResultsControllerDelegate>
-(IBAction)saveSelectedColor;
@property (nonatomic, strong) id <SelectionListViewControllerDelegate> delegate;
@end
私の選択リストに.m私は持っています:
@implementation SelectColori
@synthesize delegate;
//this method is called from a button on ui
-(IBAction)saveSelectedColore
{
[self.delegate rowChosen:[lastIndexPath row]];
[self.navigationController popViewControllerAnimated:YES];
}
別のテーブルビューからセグエを実行して、この選択リストビューにアクセスしたいと思います。
@implementation TableList
...
- (void)selectNewColor
{
SelectColor *selectController = [[SelectColor alloc] init];
selectController.delegate = (id)self;
[self.navigationController pushViewController:selectController animated:YES];
//execute segue programmatically
//[self performSegueWithIdentifier: @"SelectColorSegue" sender: self];
}
- (void)rowChosen:(NSInteger)row
{
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error Title" message:@"Error Text" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
以下を使用して選択リストに移動した場合:
[self.navigationController pushViewController:selectControllerアニメーション:YES];
アラートが表示されます。代わりに使用する場合:
[自己performSegueWithIdentifier:@ "SelectColorSegue"送信者:自己];
宛先選択リストにselectControllerを渡さないと思うので、アラートは表示されません。この問題を解決するためのアイデアはありますか?