나는 Objective-C를 가르치려고 노력 중이며 연습으로 하나의 버튼과 하나의 라벨로 앱을 작성하려고합니다. 버튼을 클릭하면 계산을 트리거 한 다음 레이블에서 결과를 확인합니다. 다음 코드는 오류나 경고없이 컴파일되고 실행되지만, 알 수있는 한 [object method] 'call'은 아무 것도하지 않습니다. 나는 이것에 시간을 보냈고 무엇이 잘못되었는지 보지 못했습니다. 누구든지 문제를 설명 할 수 있습니까? 감사.메시지에 응답 할 objective-c 객체를 가져올 수 없습니다. 내가 뭘 놓치고 있니?
*** testMethodViewController.h ** * *
#import <UIKit/UIKit.h>
#import "testBrain.h"
@interface testMethodViewController : UIViewController
{
IBOutlet UILabel *display;
testBrain *model;
}
- (IBAction)cellPressed:(UIButton *)sender;
@end
*** testMethodViewController.m ** * *
#import "testMethodViewController.h"
@implementation testMethodViewController
- (testBrain *)model
{
if (!model) {model = [[testBrain alloc] init];}
return model;
}
- (IBAction)cellPressed:(UIButton *)sender
{
int x = [model check:3]; //This method call doesn't work. But gets no errors.
NSLog(@"Results from model: %i", x); //Says x = 0, but I expect 6
NSString *xAsString = [NSString stringWithFormat: @"testBrain: %i", x];
display.text = xAsString; //Label is updated and displays: testBrain: 0
} //I expect: testBrain: 6
@end
*** testBrain.h ** * *
#import <Foundation/Foundation.h>
@interface testBrain : NSObject {}
- (int) check:(int) anInteger;
@end
*** testBrain.m ** * *
#import "testBrain.h"
@implementation testBrain
- (int) check:(int) anInteger //3 passed as the parameter.
{
int r = anInteger + anInteger;
NSLog(@"inside check %i", r); //Debugging line: doesn't print.
return r;
}
@end
잘못되었습니다. 콘센트가 없어도 버튼은 정상적으로 작동합니다.그리고 그는'-cellPressed :'에 의해 인쇄 된'NSLog'를 보았 기 때문에 그의 버튼이 제대로 연결되었는지 확인했습니다. –