您沒有傳入參數。
你應該有這樣的事情:
[self setClass1:[[[Class1 alloc] init] autorelease]];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
//This
[[self horizontalTableView] setRowHeight:[class1 CellWidth:orientation]];
當前的實現並不調用該函數的原因是因爲你沒有告訴它調用該函數。你告訴它叫[function CellWidth]
不[function CellWidth:orientation]
基於您的反饋,你實際上似乎想要更多的東西是這樣的:
-(double)CellWidth {
double width = 0;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation == UIInterfaceOrientationPortrait) {
NSLog(@"PORTRAIT");
width = 153.6;
} else if(orientation == UIInterfaceOrientationLandscapeLeft ||
orientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"LANDSCAPE");
width = 204.6;
}
return width;
}
然後在您的實現,在Class2.m:
[self setClass1:[[[Function alloc] init] autorelease]];
//This
[[self horizontalTableView] setRowHeight:[class1 CellWidth]];
爲了使這更清楚,我要嘗試收拾這個...
CoolCellInfo.h
@interface CoolCellInfo : NSObject {
}
-(double)cellWidth;
@end
CoolCellInfo.m
@implementation CoolCellInfo
-(id)init {
self = [super init];
if(self) {
}
return self;
}
-(double)cellWidth {
double width = 0;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation == UIInterfaceOrientationPortrait) {
NSLog(@"PORTRAIT");
width = 153.6;
} else if(orientation == UIInterfaceOrientationLandscapeLeft ||
orientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"LANDSCAPE");
width = 204.6;
}
return width;
}
@end
CoolCellUser.h
#import "CoolCellInfo.h"
@interface CoolCellUser : NSObject {
CoolCellInfo *cellInfo;
}
@property (nonatomic, retain) CoolCellInfo *cellInfo;
@end;
CoolCellUser.m
@implementation CoolCellUser
@synthesize cellInfo;
-(id) init {
self = [super init];
if(self) {
double width = [[self cellInfo] cellWidth];
NSLog(@"Omg cell width = %f", width);
}
return self;
}
#pragma mark Lazy Loader
-(CoolCellInfo *)cellInfo {
if(cellInfo == nil) {
[self setCellInfo:[[[CoolCellInfo alloc] init] autorelease]];
}
return cellInfo;
}
@end
你不應該將'UIInterfaceOrientation'傳遞給'CellWidth'嗎? 「 – trojanfoe
」甚至沒有調用_function_「在這裏,_function_是對象,類還是方法?嘗試使用更好的名字並解釋究竟是什麼問題。 – sidyll
是否有可能你沒有真正創建一個'Function'的實例,這意味着運行時變量'function'是'nil'? – Tommy