我創建了3層導航彈出控制器,並在第3個彈出控制器上有一個委託方法來訪問父類中的dismissPopup方法。我似乎無法調用它,我的NSLog在父類中的函數中的消息甚至沒有顯示,所以我必須使用委派錯誤或我不正確地調用它。objective C:使用委託在父類中調用函數
3個類ParentViewController有一個帶按鈕的工具欄,可調出表視圖 - > RegionViewController是帶有項目的第一個表視圖控制器 - > ConusViewController是推入導航堆棧的第二個表視圖控制器。我試圖在選擇被點擊後調用方法dismissPopover在父級方法中,因此整個popover消失。
在ConusViewController中,如果委派工作了,我會在父類的函數中看到「方法訪問」。它不顯示,所以我必須使用錯誤的委派。
對不起,我的帖子太羅嗦了,我想完成我在這裏要做的事情。謝謝。
ParentViewController.h
#import <UIKit/UIKit.h>
#import "ConusViewController.h"
@interface EnscoWXViewController : UIViewController <ConusViewControllerDelegate> {
UIPopoverController *popoverController;
IBOutlet UIWebView *webImageDisplay;
ConusViewController *cViewController;
}
@property (nonatomic, retain) UIPopoverController *popoverController;
@property (nonatomic, retain) UIWebView *webImageDisplay;
@property (nonatomic, retain) ConusViewController *cViewController;
-(IBAction) buttonShowRegion:(id) sender;
@end
ParentViewController.m
#import "ParentViewController.h"
#import "RegionViewController.h"
@implementation ParentViewController
@synthesize cViewController;
-(IBAction) buttonShowRegion:(id) sender {
...
}
-(void)dismissPopover {
[popoverController dismissPopoverAnimated:YES];
printf("Method Accessed\n");
}
- (void)viewDidLoad {
cViewController = [[ConusViewController alloc] init];
cViewController.delegate = self;
[super viewDidLoad];
}
RegionViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case 0: {
ConusViewController *conusViewController = [[ConusViewController alloc] initWithNibName:@"ConusViewController" bundle:nil];
conusViewController.contentSizeForViewInPopover = CGSizeMake(320, 350);
[self.navigationController pushViewController:conusViewController animated:YES];
[conusViewController release];
break;
}
case 1: {
break;
}
}
}
ConusViewController.h
#import <UIKit/UIKit.h>
@protocol ConusViewControllerDelegate <NSObject>
@required
- (void)dismissPopover;
@end
@interface ConusViewController : UITableViewController {
NSMutableArray *conusItems;
id delegate;
}
@property (nonatomic, assign) id <ConusViewControllerDelegate> delegate ;
@end
ConusViewController.m
#import "ConusViewController.h"
#import "ParentWXViewController.h"
@implementation ConusViewController
@synthesize delegate;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *itemRequested = [conusItems objectAtIndex:indexPath.row];
NSLog(@"logging: %@", itemRequested);
[delegate dismissPopover];
[itemRequested release];
}
什麼是'Conus'? – 2011-02-26 02:55:41