Iphone 从另一个类调用一个类
在iphonesdk中,如何从另一个类调用一个类Iphone 从另一个类调用一个类,iphone,class,Iphone,Class,在iphonesdk中,如何从另一个类调用一个类 我需要访问这个background.m类 -(void)brightness { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *image = [UIImage imageNamed:@"brightness.jpg"]; button.frame = CGRectMake(0, 0, image.size.width,
我需要访问这个background.m类
-(void)brightness
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image = [UIImage imageNamed:@"brightness.jpg"];
button.frame = CGRectMake(0, 0, image.size.width, image.size.height);
[button setImage:image forState:UIControlStateNormal];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image1 = [UIImage imageNamed:@"brightness.jpg"];
button1.frame = CGRectMake(0, 0, image1.size.width, image1.size.height);
[button1 setImage:image forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(brightnessControl:) forControlEvents:UIControlEventTouchUpInside];
gBrightnessSetting=100;
brightnessOverlay = [[CALayer alloc] retain];
brightnessOverlay.masksToBounds = YES;
brightnessOverlay.backgroundColor = [[[UIColor blackColor] colorWithAlphaComponent:1.0] CGColor];
brightnessOverlay.opacity = 0.0;
[self.layer addSublayer:brightnessOverlay];
bottomButtonsSize = SCREENWIDTH/5;
}
- (void)dealloc {
[brightnessLessButton release];
[brightnessMoreButton release];
[super dealloc];
}
- (void) setLayerFrames {
brightnessOverlay.frame = CGRectMake(self.layer.bounds.origin.x,self.layer.bounds.origin.y,self.bounds.size.width,self.layer.bounds.size.height);
}
In ebook.m class,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row]==0) {
background *back=[[background alloc] init];
[back brightness];
}
在Objective-C中,在实例上调用的方法以
-
开头,而在类上调用的方法以+
开头
例如,如果要调用构造函数方法,如NSArray中的+(NSArray*)arrayWithArray:(NSArray*)array
:
NSArray *firstArray = [[NSArray alloc] init];
NSArray *duplicateArray = [NSArray arrayWithArray:firstArray];
[duplicateArray retain];
您可能还注意到
alloc
方法以+
开头,因为它是调用类而不是实例。因为对象方法调用对象方法,所以您的问题有点难以回答。你能提供一些代码示例来说明你的意思吗?我需要访问这个背景类,不。你需要访问那个类的一个对象。不是类本身。这是正确的,初始化方法也是如此