tags:

views:

52

answers:

4

i have 2 views i m sending text in a button on 1st view to label on second view....

//////textfieldtolabelViewController.h

#import <UIKit/UIKit.h>
#import "seconview.h"

@interface textfieldtolabelViewController : UIViewController {
    IBOutlet seconview *sec;
    //IBOutlet UITextField *t1;
}

//@property(nonatomic, retain)IBOutlet UITextField *t1;
-(void)buttonclick:(id)sender;
@end

and its .m file is this

#import "textfieldtolabelViewController.h"

@implementation textfieldtolabelViewController


-(void)buttonclick:(id)sender
{
    NSString *s = [sender titleForState:UIControlStateNormal];  
    //sec.ss = s;
    [sec settext:s];
    [self presentModalViewController:sec animated:YES]; 
}
- (void)dealloc {
    [super dealloc];
}


@end

now there is second view naming seconview .h file

#import <UIKit/UIKit.h>



@interface seconview : UIViewController {
    IBOutlet UILabel *l1;

}
@property(nonatomic, retain)IBOutlet UILabel *l1;


-(void)settext:(NSString *)ss;
@end

and its .m file is ....

#import "seconview.h"


@implementation seconview
@synthesize l1;
//@synthesize ss;

-(void)settext:(NSString *)ss
{
    l1.text=ss; 
}


- (void)dealloc {
    [super dealloc];
}


@end

this program did not show any error and runs fine but problem is that the text of button in 1st view does not appear in label on second view but i made all connection perfectly.......

A: 

Most probably you didn't connect l1 to the actual label in the Interface Builder. Verify with the debugger, that l1 is not nil in your settext method

unbeli
no brother i did this finebut still not working.....please check the code and reply please.....im waiting
Online
A: 

You can include the view controller containing the label in the view controller where you want it to change, and access it by allocating a copy of it.

For example, use something like this in textfieldtolabelViewController.m

#import "seconview.h"

-(void)buttonclick:(id)sender
{
    NSString *s = [sender titleForState:UIControlStateNormal];
    seconview *viewcontroller = [[seconview alloc] initWithNibName:@"seconview" bundle:nil];
    [[viewcontroller l1] setText:s];
    [viewcontroller release];
    [self presentModalViewController:sec animated:YES]; 
}
ev0lution
A: 

I don't know what might be wrong, but have you tried using NSLog or running your code step by step to check if all of your variables' values are what you would expect?

filipe
+1  A: 

the [self presentModalViewController:sec animated:YES]; should be above the setText try it

-(void)buttonclick:(id)sender
{
    NSString *s = [sender titleForState:UIControlStateNormal];  
    //sec.ss = s;

    [self presentModalViewController:sec animated:YES];


    [sec settext:s];

}

hope it will work....

Ranjeet Sajwan