7
我在實現選擇列表時遇到了集成segue和協議時遇到的一些問題。正確訪問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 animated:YES];
顯示警報。如果我改用:
[self performSegueWithIdentifier:@「SelectColorSegue」sender:self];
沒有提示顯示,因爲我認爲我不會將目標選擇列表傳遞給selectController。有什麼想法來解決這個問題嗎?
它像一個魅力工作謝謝你! :) – yassassin 2011-12-17 10:19:47