我已经完成了一个具有 NewClass.h/.m ViewController.h/.m 的单视图项目:
新类.h:
#import <Foundation/Foundation.h>
@interface NewClass : NSObject
-(void)String2;
@end
新类.m
#import "NewClass.h"
@implementation NewClass
-(void)String2
{
NSLog(@"it works");
}
@end
视图控制器.h:
enter code here
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
视图控制器.m:
enter code here
#import "ViewController.h"
#import "NewClass.h"
@interface ViewController ()
@property (strong) NewClass *obj;
@end
@implementation ViewController
@synthesize obj = _obj;
- (void)viewDidLoad
{
[super viewDidLoad];
[self.obj String2];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
问题是该程序不起作用。我没有看到“它有效”。ViewController 看到了一个 obj 的方法,但是 NewClass 没有传递任何东西。请问有人能帮帮我吗??????