I passed a variable from first.m to seViewController.m. I'm able to print that variable using NSLog(@variable) but I'm unable to use textField.text=variable. How to print that variable in a te开发者_StackOverflow社区xtbox?
-(void)insert:variable
{
NSLog(@"%@",variable);
textfield.text=variable;
}
In my text box value is not coming...
You can try
textfield.text=[variable description]; // or -localizedDescription
That's what is used when you print your object using NSLog.
However it may be more appropriate to get some textual attributes from your object and then assign them to textField. That will depend, of course, of what type your variable is, what info it contains and how you want to print it...
Try This code:
-(void)insert:(NSString*) variable
{
NSLog(@"%@",variable);
textfield.text=[NSString stringWithFormat:@"%@",variable];
}
Try with below
-(void)insert:(NSString*) variable
{
NSLog(@"%@",variable);
textfield.text=variable;
}
You don't indicate variable
's type in your code snippet (is that valid Objective-C syntax?). If it's an NSString
, your code should work as is. If it's any object type (including NSString
), you can use the description
method to get a descriptive string.
If it's a C primitive (int
, float
, etc.) you will have to create an NSString (possibly using [NSString stringWithFormat]
.
精彩评论