Objective-C的新手可能会做一些错误的事情。 我试图从ViewController上的NSObject调用一个方法,这里是我的代码。
ViewController.h
-(void)loadBarNavButtons;
ViewController.m
#import "ViewController.h"
#import "Constants.h"
#import "Utils.h"
#import "DesignStyle.h"
#import "SocialConnection.h"
@implementation ViewController{
SocialConnection *SC;
}
- (void)viewDidLoad
{
// enables use of social connection
SC = [[SocialConnection alloc] init];
[SC setup:self]; // pass in the UIVIEWCONTROLLER - could not find another way to do this?
// not sure if correct.
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
// method being called from NSObject
-(void)loadBarNavButtons{
// DO Something here
}
SocialConnection.m
@implementation SocialConnection{
UIView* view;
UIViewController* controller;
}
// the setup function passes in a view controller
-(void)setup:(UIViewController*)UIController{
controller = UIController;
view = controller.view;
}
// setup when the user is logged in
//FIXME: This is the line that is broken
-(void)isLoggedIn{
NSLog(@"Loggged in!");
[controller loadBarNavButtons];
}
给我以下错误:
'UIViewController'的无可见@interface声明了选择器 'loadBarNavButtons'
我明白它找不到方法。 是否在.h文件中定义不正确?
答案 0 :(得分:0)
您的控制器是UIViewController
的实例。您可能希望它是ViewController
的实例。
顺便说一下:你应该试着对你的名字更加冗长。