在UILabel Xcode中显示NSLog结果 [英] Display NSLog result in UILabel xcode
本文介绍了在UILabel Xcode中显示NSLog结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有RootCtrl&详细信息Ctrl.在RootCtrl上,我有一个uiTableview.我使用此函数编写选择的结果:
I have RootCtrl & DetailCtrl. On RootCtrl, I have a uiTableview. I use this function to write the result of the choice :
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(@"%@",cell.textLabel.text);
插入 didSelectRowAtIndexPath .我想将UILabel中的NSLog结果显示到Detailctrl中,以便显示另一个视图.我该怎么办?
into didSelectRowAtIndexPath. I'd like to display the NSLog result in UILabel into Detailctrl, so an another view. How I can do it ?
推荐答案
在 RootViewController
中输入以下代码:
Input the code below in the RootViewController
:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString*yourStringNameHere = [NSString stringWithFormat:@"%@",cell.textLabel.text];
NSLog(@"%@",yourStringNameHere);//this isn't used in retreiving the info
NSNumber *number = [NSNumber numberWithInt:1];
NSDictionary *yourDictionaryNameHere = [NSDictionary dictionaryWithObjectsAndKeys:
yourStringNameHere, @"yourStringNameHereDictionary",nil];
在 DetailViewController
中输入以下代码:
Input the code below in the DetailViewController
:
在头文件(.h)中放置
In the header file(.h) put
IBOutlet UILabel *yourLabelNameHere;
在主文件(.m)中使用
In the main file(.m) use
yourLabelNameHere.text= [yourDictionaryNameHere objectForKey:(@"yourStringNameHereDictionary")];
注释:
- 如果您无法访问字典,请输入#import"RootViewController.h"
- 我们使用NSDictionary 将数据存储在iPhone内存中,这使我们可以使用其他类中的数据,否则仅使用#import只能从变量的初始化中接收数据.
- 通过密钥从NSDictionary接收字符串
- 在
DetailViewController.h
中设置一个UILabel,该UILabel输出到一个故事板或xib文件 - 要在过渡开始时加载标签,请将字典接收器放在
ViewDidLoad
或ViewDidLoad调用的方法(
-((void)function)
)中
- If you can't have access the dictionary put #import "RootViewController.h"
- We use the NSDictionary to store data on the iPhone memory, this allows us to use the data from the other class, otherwise with just using #import you only receive the data from the initialization of the variable.
- Receive a string from the NSDictionary from a key
- Set up a UILabel in the
DetailViewController.h
that outputs to a storyboard or xib file - For loading the label at the start of the transition, put the dictionary receiver in
ViewDidLoad
or a method(-(void)function)
called byViewDidLoad
这篇关于在UILabel Xcode中显示NSLog结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文