在实现选择列表时,我在集成 segue 和协议时遇到了一些问题。
在我的选择列表 .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];
}
我想通过从另一个表视图执行 segue 来访问此选择列表视图:
@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];
显示警报。如果我改为使用:
[self performSegueWithIdentifier:@“SelectColorSegue”发件人:self];
没有显示警报,因为我认为我没有将 selectController 传递给目标选择列表。请问有什么想法可以解决这个问题吗?