简体   繁体   English

UILabel没有显示UITableview中的值

[英]UILabel is not showing values from the UITableview

Sorry guys its me again. 抱歉,我又来了。

In my project i used UITableview for showing weather.so, I need to show the first row text to UILabel without any button action or watever. 在我的项目中,我使用UITableview来显示weather.so,因此我需要向UILabel显示第一行文本,而无需执行任何按钮操作或操作。 I just want cell text to UILabel without any action. 我只希望将单元格文本发送到UILabel而无需任何操作。

ex: In the tableview first cell showing text as "Lovely IOS" I want to show the same text to UILABEL without any action. 例如:tableview的第一个单元格中,将文本显示为“ Lovely IOS”,我希望对UILABEL显示相同的文本,而无需执行任何操作。 I took UILabel in the xib. 我在xib中接过UILabel Thanks in advance 提前致谢

Any sample code please. 请提供任何示例代码。

you only set action for particular cell 您只为特定单元格设置操作

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


  if (indexPath.row == 1){
 //set action for cell
}
}

In the method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath equate 在方法中- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

 cell.textLabel.text = [array objectAtIndex:indexPath.row]; 
 LabelName.text= cell.textLabel.text;

You have the data for your cell so what's a big to UIlabel .You just need to set the same text there. 您拥有单元格的数据,所以UIlabel的意义很大。您只需要在UIlabel设置相同的文本即可。 Updated :- 更新 :-

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = cell.textLabel.text;

you will get the text. 您将收到文本。

You have two options for this either you add add UILable or set the text to he cell.textLabel.text in the following method. 为此,您有两个选择,或者添加add UILable或通过以下方法将文本设置为cell.textLabel.text。 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM