0
我已经设置了一个委托方法来从我的masterViewController
到我的detailViewController
进行通信,但委托方法没有被调用。UISplitView中的代表没有被调用
MasterViewController.h
#import <UIKit/UIKit.h>
@class DetailViewController;
@class MasterViewController;
@protocol MasterViewControllerDelegate
- (void)SelectionChanged:(NSString *)url;
@end
@interface MasterViewController : UITableViewController
@property (nonatomic, weak) id<MasterViewControllerDelegate> delegate;
@property (strong, nonatomic) DetailViewController *detailViewController;
@end
然后在我的MasterViewController.m我合成委托:
@synthesize delegate;
最后我打电话从我didSelectRowAtIndexPath方法方法,像这样的委托方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *links = [NSArray arrayWithObjects:
@"http://www.link1.com",
@"http://www.link2.com",
@"http://www.link3.com",
nil];
[self.delegate SelectionChanged:[links objectAtIndex: indexPath.row]];
}
然后在我的DetailViewController.h中我有:
@interface DetailViewController : UIViewController <UISplitViewControllerDelegate, MasterViewControllerDelegate>
而且在DetailViewController.m:
- (void)SelectionChanged:(NSString *)url {
NSLog(@"URL is %@", url);
}
当我运行应用程序,从SelectionChanged
的NSLog
,不会被调用我没有得到任何错误。有任何想法吗?
你确定'self.delegate'不是零吗? – Saphrosit 2012-01-07 02:04:01
我刚测试过它,果然,self.delegate是(null)。我想我应该明白为什么这是... – 2012-01-07 02:23:19
似乎无法弄清楚我的委托是空....呃。 – 2012-01-07 03:56:07