为了在按钮上创建翻转效果,我创建了一个名为Button的NSButton子类.
Button.h:
#import <AppKit/AppKit.h>
@interface Button : NSButton {
}
- (void)mouseEntered:(NSEvent *)theEvent;
- (void)mouseExited:(NSEvent *)theEvent;
- (void)mouseDown:(NSEvent *)ev;
- (void)mouseUp:(NSEvent *)theEvent;
@end
Run Code Online (Sandbox Code Playgroud)
Button.m:#import"Button.h"
@implementation Button
- (id)initWithFrame:(NSRect)frameRect {
self = [super initWithFrame:frameRect];
if(self != nil) {
NSLog(@"btn init");
}
return self;
}
- (void)mouseEntered:(NSEvent *)theEvent{
NSLog(@"mouseEntered");
[self setImage:[NSImage imageNamed:@"lockIcon_2.png"]];
[self setNeedsDisplay];
}
- (void)mouseExited:(NSEvent *)theEvent{
[self setImage:[NSImage imageNamed:@"lockIcon_1.png"]];
NSLog(@"mouseExited");
[self setNeedsDisplay];
}
- (void)mouseDown:(NSEvent *)ev {
NSLog(@"mouseDown!");
}
- (void)mouseUp:(NSEvent *)ev {
NSLog(@"mouseUp!");
}
@end
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,每次我点击一个按钮,我在日志中看到"mouseDown",但我没有看到"mouseEntered"或"mouseExited"(当然看不到图像更改)?? 可悲的是,我知道我错过了一些明显的东西,但我只是没有看到它...... ???
好吧......凌晨2点,这是我划线的地方.帮助......在我的笔记本电脑最终走出窗外之前.:)
我已经尝试过使用setTimer,回调以及我能想到的其他一切(当然还有其他一些Stackoverflow提示).我已经删除了所有内容,所以我只留下基本代码.
我要做的是调用parseRow()并在最后保存记录之前,我需要获取相关的类别(通过AJAX); 然而,它吹过它,所以类别总是"未定义".
function parseRow(row){
var rowArray = row.trim().split(",");
var date = rowArray[0];
var checknum = rowArray[1];
var payee = rowArray[2];
var memo = rowArray[3];
var amount = rowArray[4];
//ERROR: blows right past this one and sets the category variable BEFORE ajax returns
var category = autoSelectCategory(payee);
saveRecord(date, checkNum, payee, memo, category, payment, deposit);
}
function autoSelectCategory(payee) {
var data;
$.ajax({
async: false,
url: "autoselectcategory",
dataType: "json",
data: {
string: payee
},
success: function (returnedData) {
data = returnedData; …Run Code Online (Sandbox Code Playgroud)