从按钮调用功能

时间:2013-09-26 14:56:59

标签: ios uibutton

任何人都可以帮我理解我的功能在pls下面出了什么问题吗?

我对本地IOS开发相当新手。

我想使用本教程(http://www.appcoda.com/ios-programming-sidebar-navigation-menu/)在我们的应用中实现侧面板 所有这一切都很好,并且很简单 - 但我想通过标准按钮而不是标题中的动态按钮来触发显示功能 - 以适应我们的设计..

原始代码如下 -

#import "SWRevealViewController.h"


// Change button color
_sidebarButton.tintColor = [UIColor colorWithWhite:0.96f alpha:0.2f];

// Set the side bar button action. When it's tapped, it'll show up the sidebar.
_sidebarButton.target = self.revealViewController;
_sidebarButton.action = @selector(revealToggle:);

// Set the gesture
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

复制由按钮触发的功能我将以下内容添加到.h文件 -

@property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;

@property (weak, nonatomic) IBOutlet UIButton *revealLeftBtn;
- (IBAction)btnClickRevealL:(id)sender;

以及我的.m文件中的以下内容

- (IBAction)btnClickRevealL:(id)sender {


[self.revealViewController];
[@selector(revealToggle:)];

}

我得到上述行的错误'疑似标识符' - 我不明白用前面的方法触发的函数如何而不是上面的 - 有人可以帮忙吗? 干杯

作为参考,这是整个.M文件 -

#import "MainViewController.h"
#import "SWRevealViewController.h"


@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad
{
[super viewDidLoad];

self.title = @"";

// Change button color
_sidebarButton.tintColor = [UIColor colorWithWhite:0.96f alpha:0.2f];

[self.navigationController.navigationBar setTranslucent:TRUE];

// Set the side bar button action. When it's tapped, it'll show up the sidebar.






// Set the gesture
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];




}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)btnClickRevealL:(id)sender {


[self.revealViewController];
[@selector(revealToggle:)];

}
@end

2 个答案:

答案 0 :(得分:8)

这一行:

 (IBAction)btnClickRevealL:(id)sender {


[self.revealViewController];
[@selector(revealToggle:)];

}

什么都不做。

我想这就是你想要做的事情:

[self.revealViewController revealToggle:sender];

当您设置按钮的targetaction时,您可以设置正在执行操作的类(target)以及调用的方法(action

这相当于做[target action]

答案 1 :(得分:0)

- (IBAction)logInBtnClicked:(id)sender {
    //Remove WhiteSpace from start of uitextfield
    self.emailIdTxtFldRef.text = [self.emailIdTxtFldRef.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
    self.passwordTxtFldRef.text = [self.passwordTxtFldRef.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
    if ([self.emailIdTxtFldRef.text isEqualToString:@""]||[self.passwordTxtFldRef.text isEqualToString:@""]) {
        [self showMessage:@"All fields are mandatory" withTitle:@"Error"];
    }else{
        SWRevealViewController *revealVC = [self.storyboard instantiateViewControllerWithIdentifier:@"swRevealViewContoller"];
        revealVC.delegate=self;
        [[UIApplication sharedApplication]keyWindow].rootViewController = revealVC;
    }
}