我做了一個單一視圖項目有NewClass.h/.M ViewController.h/.M:Objective-C的傳球數據
NewClass.h:
#import <Foundation/Foundation.h>
@interface NewClass : NSObject
-(void)String2;
@end
NewClass.m
#import "NewClass.h"
@implementation NewClass
-(void)String2
{
NSLog(@"it works");
}
@end
ViewController.h:
enter code here
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
ViewController.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不傳遞任何東西。請任何人都可以幫助我??????
請注意'String2'應該只是'string2';方法以小寫字母開頭。 – bbum 2012-08-08 14:56:06