EDit:
我有带有两个选项卡的选项卡控制器,第一个选项卡有一个viewController,第二个选项卡有带有的navigationViewController和带有tableView的两个ViewControllers堆栈。
表1->VC1
Tab2 2-->NVC
我要推的代码:
fistVC1.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0 & (indexPath.row == 0)) {
_secondVC2 = [[secondVC2 alloc] init];
[self.navigationController pushViewController:_secondVC2 animated:YES];
[_secondVC2 release];我需要做的是将VC1设置为secondVC2的委托,当选择secondVC2单元时,我想向VC1发送消息。
我该怎么做,请给我一些建议。
我试着吹牛:
secondVC2.h
@protocol secondVC2Delegate <NSObject>
- (void)someMethod;
@end
#import <UIKit/UIKit.h>
@interface secondVC2 :UIViewController<UITableViewDelegate,UITableViewDataSource>
{
id<secondVC2Delegate>delegate;
}
@property (nonatomic ,assign) id<secondVC2Delegate>delegate;
@end;secondVC2.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"delegate%@",self.delegate);
if (indexPath.row == 0) {
[self.delegate someMethod];
}VC1.h
#import <UIKit/UIKit.h>
#import"secondVC2"
@interface VC1 :UIViewController<secondVC2Delegate>{
secondVC2 *tvc2;
}
@property (nonatomic ,retain) secondVC2 *tvc2;
- (void)someMethod;
@end;VC1.m
- (void)viewDidLoad
{
tvc2 = [secondVC2 alloc] init];
tvc2.delegate = self;
}但是这个代表一直被释放,我在secondVC2中得到了零的委托,我不知道为什么。所以我怎么能做到这一点?
发布于 2013-07-17 02:27:53
ViewController1 *viewController1 = [[ViewController1 alloc] init];
ViewController2 *viewController2 = [[ViewController2 alloc] init];
viewController1.delegate = viewController2;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController2];
[self.tabBarController setViewControllers:@[viewController1, navigationController]];您还可以查看NSNotificationCenter。
https://stackoverflow.com/questions/17689964
复制相似问题