0

enter image description here

As my Screen shot show that i have UIButton on SliderValueViewController.xib.i want that when i click on this UIButton it automatically addsubview (which name is detailview) in Secondview.xib.here is my code. in SliderValueViewController.h i declare my protocol,

#import <UIKit/UIKit.h>
@protocol Testmyview

-(void)displayview;

@end


@interface SliderValueViewController : UIViewController {

    IBOutlet UILabel *sliderValue;
    IBOutlet UIButton *btngo;
        id <Testmyview> delegate;
}

@property (nonatomic, retain) IBOutlet UILabel *sliderValue;
@property (nonatomic, assign)id <Testmyview> delegate;

-(void)updateSliderValueTo:(CGFloat)_value;
-(IBAction)gotodetailview;
@end

And in SliderValueViewController.m

           #import "SliderValueViewController.h"
           #import"secondview.h"
           @implementation SliderValueViewController
           @synthesize sliderValue;
           @synthesize delegate;

And here is my Button funcion..

    -(IBAction)gotodetailview
      {
         [self.delegate displayview];
      }

Now my secondview.h

enter image description here

And my secondview.m look just like this..

   #import "secondview.h"
   #import "SliderValueViewController.h"
   #import "ELCSlider.h"
   @implementation secondview

And here is my funciton that i want..

  -(void)displayview
    {
      [self.view addSubview:detailview];    
   }

In ELSLiderl.m i do this..

 -(id)initWithCoder:(NSCoder *)aDecoder {

 if(self = [super initWithCoder:aDecoder]) {
    [self addTarget:self action:@selector(valueChanged) forControlEvents:UIControlEventValueChanged];
    sliderValueController = [[SliderValueViewController alloc] initWithNibName:@"SliderValueViewController" bundle:[NSBundle mainBundle]];
    popoverController = [[UIPopoverController alloc] initWithContentViewController:sliderValueController];
    [popoverController   setPopoverContentSize:sliderValueController.view.frame.size];
     }

    return self;    
   }

 -(void)valueChanged {

[sliderValueController updateSliderValueTo:self.value];

CGFloat sliderMin =  self.minimumValue;
CGFloat sliderMax = self.maximumValue;
CGFloat sliderMaxMinDiff = sliderMax - sliderMin;
CGFloat sliderValue = self.value;

if(sliderMin < 0.0) {

    sliderValue = self.value-sliderMin;
    sliderMax = sliderMax - sliderMin;
    sliderMin = 0.0;
    sliderMaxMinDiff = sliderMax - sliderMin;
}

CGFloat xCoord = ((sliderValue-sliderMin)/sliderMaxMinDiff)*[self frame].size.width-sliderValueController.view.frame.size.width/2.0;

CGFloat halfMax = (sliderMax+sliderMin)/2.0;

if(sliderValue > halfMax) {

    sliderValue = (sliderValue - halfMax)+(sliderMin*1.0);
    sliderValue = sliderValue/halfMax;
    sliderValue = sliderValue*11.0;

    xCoord = xCoord - sliderValue;
}

else if(sliderValue <  halfMax) {

    sliderValue = (halfMax - sliderValue)+(sliderMin*1.0);
    sliderValue = sliderValue/halfMax;
    sliderValue = sliderValue*11.0;

    xCoord = xCoord + sliderValue;
}

[popoverController presentPopoverFromRect:CGRectMake(xCoord, 0, sliderValueController.view.frame.size.width, sliderValueController.view.frame.size.height) inView:self permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
 }

Using this all this Code it give me NO worning or Error,but it did not addsubview .when i use breakpoint my UIButton method(-(IBAction)gotodetailview) called but its not call delegate methodmethod (-(void)displayview) in secondview .Can any one help what mistake i make .thanx in advance.

jamil
  • 2,419
  • 3
  • 37
  • 64

1 Answers1

2

In secondview.m

you seem that you forgot to set the delegate property of SliderValueViewController

In the function that presents or pushes the "SliderValueViewController" You will have some thing like this

SliderValueViewController *controller = [[SliderValueViewController alloc] init];
//You will need to add this code
//self is secondview
controller.delegate = self;

Now when [self.delegate displayview]; get calls, this will call displayview in secondview

Omar Abdelhafith
  • 21,163
  • 5
  • 52
  • 56
  • @Omer thanx for helping so for..but i have no such fuction in secondview that presents or pushes ther "SliderValueViewController" bcz i call "SliderValueViewController" in my "ELCSlider" as u looking in screen shot..please check it bcz this problem struck me from last 4 hours.. – jamil Jun 09 '12 at 13:45