从另一个类调用一个类

时间:2011-01-25 03:37:43

标签: iphone class

在iphone sdk中如何从另一个类调用一个类?

我需要访问这个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];

    }

1 个答案:

答案 0 :(得分:1)

在Objective-C中,在实例上调用的方法以-开头,而在类上调用的方法以+开头。

例如,如果您想在NSArray中调用构造函数方法,例如+ (NSArray *)arrayWithArray:(NSArray *)array

NSArray *firstArray = [[NSArray alloc] init];
NSArray *duplicateArray = [NSArray arrayWithArray:firstArray];
[duplicateArray retain];

您可能还注意到alloc方法以+开头,因为它是在类上调用的,而不是实例。