Hi all, I created a segmented control with 2 segments(button,textfield).I need to load only the selected segment on to the screen below the segmented control.When i select button first and textfield second, button should not appear on the screen and is same for the textfield. I tried with "hidden" and "removeFromSuperview" but not worked. So please help me.
CODE:
// segmentedControl.m which is a UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UISegmentedControl *segmentcontrol=[[ UISegmentedControl alloc ] initWithItems:
[NSArray arrayWithObjects:@"Buttons",@"TextField",@"Picker" ,@"TableView",nil]];
segmentcontrol.frame=CGRectMake(100,10,600,80);
segmentcontrol.selectedSegmentIndex=6;
[segmentcontrol addTarget:self
action:@selector(action

forControlEvents:UIControlEventAllEvents];
[self.view addSubview:segmentcontrol];
}
- (void)action

id)sender
{
NSLog(@"Segment %d selected", [sender selectedSegmentIndex]);
iButtons *button=[[iButtons alloc] initWithFrame:CGRectMake(0,200,400,400)];
iTextField *textfield=[[iTextField alloc]initWithFrame:CGRectMake(0,200,400,400)];
if ([sender selectedSegmentIndex]==0)
{
[button mymethod:NO];
[self.view addSubview:button];
}
if([sender selectedSegmentIndex]==1)
{
[button mymethod:YES];
[textfield mymethod]; // mymethod implements textfield
[self.view addSubview:textfield];
}
}
//iButtons.m file UIView File
-(id)initWithFrame

CGRect)frame
{
if ((self = [super initWithFrame:frame ]))
{
NSLog(@"inside init.iButtons");
}
return self;
}
-(void)mymethod

BOOL)hide
{
NSLog(@"myMethod");
if(hide==NO)
{
label1=[[UILabel alloc] initWithFrame:CGRectMake(100,100,300,60)];
label1.text=@"RoundedRectangle";
label1.textColor=[UIColor whiteColor];
label1.backgroundColor=[UIColor blackColor];
label1.font=[UIFont systemFontOfSize:30];
[self addSubview:label1];
roundedRectangle=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[roundedRectangle addTarget:self action:@selector(buttonclick) forControlEvents:UIControlEventTouchDown];
roundedRectangle.frame=CGRectMake(480,100,100,90);
[roundedRectangle setTitle:@"Button" forState:UIControlStateNormal];
[self addSubview:roundedRectangle];
}
if(hide==YES)
{
[label1 removeFromSuperview];
[roundedRectangle removeFromSuperview];
}
return self;
}
Thanks in advance.
Santosh.