user579911
user579911

Reputation: 63

calling a class from another class

In iphone sdk how to call a class from another class?

i need to access this background.m class,

-(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];

    }

Upvotes: 0

Views: 214

Answers (1)

Alan Zeino
Alan Zeino

Reputation: 4396

In Objective-C, methods that are invoked upon an instance begin with a -, whereas methods invoked upon a class begin with +.

For example, if you wanted to call a constructor method such as + (NSArray *)arrayWithArray:(NSArray *)array in NSArray:

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

You might also notice that the alloc method begins with a +, since it is called upon a class, not an instance.

Upvotes: 1

Related Questions