2012-10-29 36 views
0

我打开一个视图控制器(带导航栏和关闭视图控制器栏按钮项)。这是视图控制器是用于向用户显示信息时,他点击了“帮助”按钮。导航是这样的:ViewController1 - >“帮助”按钮 - > Viewcontroller2。 Viewcontroller2有一个关闭按钮,关闭这个ViewController。我有一个IBAction关闭按钮的文件所有者的关闭按钮,但是当我点击'关闭'按钮时,中断点没有被击中。该代码是:按钮关闭UIViewController中单击

DetailViewController.m(viewcontroller1):

-(void) showHelp:(id)sender 
{ 
    HelpViewController *helpWindow = [[HelpViewController alloc]initWithNibName:@"HelpViewController" bundle:[NSBundle mainBundle]]; 
    helpWindow.modalPresentationStyle = UIModalPresentationFormSheet; 
    [self presentModalViewController:helpWindow animated:YES]; 
} 

HelpViewController.m(viewcontroller2):

#import "HelpViewController.h" 

@interface HelpViewController() 

@end 

@implementation HelpViewController 

@synthesize scrollView; 


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (IBAction)closeAction:(id)sender { 
    [self dismissModalViewControllerAnimated:YES]; 

} 

@end 

我试图把一个断点 “closeAction” 但它不是击中。我是iOS开发新手。我错过了一些非常明显的东西。任何帮助表示赞赏!

回答

1

点击您的Close按钮,然后选择右侧工具中的connection inspector选项卡。在touchUpInside模式下检查您的按钮是否与closeAction:连接。

如果没有,则将您的UIButton插座连接到此方法-(IBAction)closeAction:(id)sender;然后尝试。

UPDATE:如果您的按钮是UIBarButtonItem,那么将会有一个选项为"New referencing outlet"。从中拖拽并连接你的方法。

+0

“关闭”按钮“栏按钮项目”导航Bar.When里面我点击连接督察“关闭”按钮,没有“touchUpInside”的选项。我有一个IBOutlet在.h和IBAction也在同一个.h文件中。我如何将它们连接到对方? – user1550951

+0

现在检查我的答案... –

+0

我很抱歉听起来像一个nOOb!当我点击“新引用插座”并拖动到“关闭”按钮,方法名称doesnt显示。我应该这样做的不同? – user1550951