Ios viewcontroller上的NSObject调用方法
对于Objective-C来说,这是一个全新的概念,所以可能有一些地方做错了。 我正在尝试从viewcontroller上找到的NSObject调用一个方法。下面是我的代码 ViewController.hIos viewcontroller上的NSObject调用方法,ios,objective-c,Ios,Objective C,对于Objective-C来说,这是一个全新的概念,所以可能有一些地方做错了。 我正在尝试从viewcontroller上找到的NSObject调用一个方法。下面是我的代码 ViewController.h -(void)loadBarNavButtons; ViewController.m #import "ViewController.h" #import "Constants.h" #import "Utils.h" #import "DesignStyle.h" #import "So
-(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
}
@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];
}
SocialConnection.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
}
@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声明选择器
“加载按钮”
我知道它找不到方法。
是否在.h文件中定义不正确?您的控制器是
UIViewController
的实例。您可能希望它是ViewController
的一个实例
顺便说一句:你应该尽量把你的名字说得更详细些