你们不会通过一个参数。
You should have something like this:
[self setClass1:[[[Class1 alloc] init] autorelease]];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
//This
[[self horizontalTableView] setRowHeight:[class1 CellWidth:orientation]];
The reason your current implementation isn t calling that function is because you aren t telling it to call that function. You re telling it to call [function CellWidth]
not [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;
}
then in your implementation, in Class2.m:
[self setClass1:[[[Function alloc] init] autorelease]];
//This
[[self horizontalTableView] setRowHeight:[class1 CellWidth]];
为了更清楚地说明这一点,我将尝试并清理这件事。
CoolCellInfo.h
@interface CoolCellInfo : NSObject {
}
-(double)cellWidth;
@end
gilCellInfo.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