Question

I would like to create a new uitextview every time when the user click on the same uibutton.

I've tried to write some codes but I can create one uitextview only. Would be glad if there's some sample code that can be provided to help me out.

Thanks in advance.

    UITextView *newTextView =[[UITextView alloc]init];
    newTextView.frame=CGRectMake(0,0,100,100);
    [textView addSubview:newTextView];
    newTextView.delegate=self;
    [newTextView release];
Was it helpful?

Solution

In case of your code will create the new textView as you required but it will overlap the last one so you can see that new . you need to create int y variable increase the value everytime then will change the y codinate of your textView.

-(IBAction)addTView:(id)sender  {
    UITextView *newTextView =[[UITextView alloc]init];
    newTextView.frame=CGRectMake(0,y,100,100);
    [textView addSubview:newTextView];
    newTextView.delegate=self;
    [newTextView release];
    y = y + 100; 
}

then add it On your View where you want to add using [self.view addSubView: yourView]

OTHER TIPS

-(IBAction)textviewadd:(id)sender  {
UITextView *View =[[UITextView alloc]init];
newTextView.frame=CGRectMake(0,y,100,100);
[self.view addSubview:txtView];
txtView.delegate=self;
[txtView release];
y = y + 150; 
}

i hope this code useful for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top