IB动作无法在点击后捕捉到我的事件,将按钮标识设置为buttonEn,将en设置为touchUPInside事件方法......但仍然没有响应被触发。
以下是我的代码:
- (IBAction)en:(id)sender {
NSLog(@"enter");
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test_en.xls" ofType:@"xls"];
NSURL *url = [NSURL URLWithString:filePath];
QZWorkbook *excelReader = [[QZWorkbook alloc] initWithContentsOfXLS:url];
NSArray *sheets =excelReader.workSheets;
NSMutableArray *words = [[NSMutableArray alloc] init];
for(int i = 0 ; i < [sheets count] ; i ++){
QZWorkSheet *sheet = [sheets objectAtIndex:i];
NSArray *columns = [ sheet columns];
NSArray *rows = columns.firstObject;
for(int j = 0 ; j < [rows count] ; j ++){
QZCell *nextObject = [ rows objectAtIndex:j ] ;
[words addObject: nextObject.content ];
}
}
// buttonDe.se
[buttonEn setTitle: [words objectAtIndex:0] forState: UIControlStateNormal];
[buttonDe setTitle: [words objectAtIndex:1] forState: UIControlStateNormal];
[buttonFr setTitle: [words objectAtIndex:2] forState: UIControlStateNormal];
[buttonEp setTitle: [words objectAtIndex:3] forState: UIControlStateNormal];
[buttonNd setTitle: [words objectAtIndex:4] forState: UIControlStateNormal];
[buttonJp setTitle: [words objectAtIndex:5] forState: UIControlStateNormal];
[label1 setText:[words objectAtIndex:6] ];
[label2 setText:[words objectAtIndex:7] ];
QZWorkSheet *firstWorkSheet = excelReader.workSheets.firstObject;
[firstWorkSheet open];
NSLog(@"%@", firstWorkSheet.rows.firstObject);
}
答案 0 :(得分:0)
您应该检查IBOutlet是否与按钮和方法正确连接。 在方法上应用断点并检查指针是否转到方法。
<强> ViewController.h 强>
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UIButton *test;
}
-(IBAction)en:(id)sender;
@end
<强> ViewController.m 强>
#import“ViewController.h”
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
\[super viewDidLoad\];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
\[super didReceiveMemoryWarning\];
// Dispose of any resources that can be recreated.
}
- (IBAction)en:(id)sender {
// NSLog(@"enter");
// NSString *filePath = \[\[NSBundle mainBundle\] pathForResource:@"test_en.xls" ofType:@"xls"\];
// NSURL *url = \[NSURL URLWithString:filePath\];
// QZWorkbook *excelReader = \[\[QZWorkbook alloc\] initWithContentsOfXLS:url\];
// NSArray *sheets =excelReader.workSheets;
// NSMutableArray *words = \[\[NSMutableArray alloc\] init\];
//
// for(int i = 0 ; i < \[sheets count\] ; i ++){
// QZWorkSheet *sheet = \[sheets objectAtIndex:i\];
// NSArray *columns = \[ sheet columns\];
// NSArray *rows = columns.firstObject;
// for(int j = 0 ; j < \[rows count\] ; j ++){
// QZCell *nextObject = \[ rows objectAtIndex:j \] ;
// \[words addObject: nextObject.content \];
// }
// }
// // buttonDe.se
//
// \[buttonEn setTitle: \[words objectAtIndex:0\] forState: UIControlStateNormal\];
// \[buttonDe setTitle: \[words objectAtIndex:1\] forState: UIControlStateNormal\];
// \[buttonFr setTitle: \[words objectAtIndex:2\] forState: UIControlStateNormal\];
// \[buttonEp setTitle: \[words objectAtIndex:3\] forState: UIControlStateNormal\];
// \[buttonNd setTitle: \[words objectAtIndex:4\] forState: UIControlStateNormal\];
// \[buttonJp setTitle: \[words objectAtIndex:5\] forState: UIControlStateNormal\];
//
// \[label1 setText:\[words objectAtIndex:6\] \];
// \[label2 setText:\[words objectAtIndex:7\] \];
//
// QZWorkSheet *firstWorkSheet = excelReader.workSheets.firstObject;
// \[firstWorkSheet open\];
// NSLog(@"%@", firstWorkSheet.rows.firstObject);
}
@end
只需创建一个测试项目并使用名称和方法复制粘贴此IBOutlet上的代码和链接按钮。如果此工作正常,那么您的实现就会出现问题。
答案 1 :(得分:0)
首先将UIButton从对象库拖到storyboard或xib中。
然后单击辅助编辑器。右上角的中间标签。
然后将按钮连接拖到文件的.h类,您必须执行按钮操作。然后将连接类型插座更改为操作,设置按钮操作方法名称,然后更改事件然后连接按钮。
按钮操作方法将出现在.m文件中
用于交叉检查方法操作中的打印问候按钮
- (IBAction)buttonAction:(id)sender
{
NSLog(@"hello button");
}
从.m文件中删除不必要的按钮相关代码
希望它会对你有所帮助。