简体   繁体   English

当我选择单元格时如何向另一个视图控制器发送一些值?

[英]How to send some value to another view controller when i select cell?

I have two View Controllers: MainScreenViewController and TargetScreenViewController ; 我有两个视图控制器: MainScreenViewControllerTargetScreenViewController

In MainScreenViewController I have UITableView with custom cells, in TargetScreenViewController I have the label which i need change. MainScreenViewController我具有带有自定义单元格的UITableView ;在TargetScreenViewController我具有需要更改的标签。

I need to get some value, index path for example, and pass it along to TargetScreenViewController and change the label based on that value. 我需要获取一些值,例如索引路径,并将其传递给TargetScreenViewController并根据该值更改标签。

I already setup the push segue in Triggered Segues in cell, but how can i pass some value and get it there? 我已经在单元格中的触发的Segues中设置了推送Segue,但是如何传递一些值并将其传递到那里?

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

    TargetView *target = [[TargetView alloc]initWithNibName:@"TargetView" bundle:nil];

    NSString *data = @"Success";

    target.incomingData = data;

}

in TargetView: 在Tar​​getView中:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.mLabel.text = self.incomingData;
}

but label is blank =[ 但标签为空= [

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    Class *yourObject=[self.arr objectAtIndex:indexPath.row];

    TargetView *vc=[[TargetView alloc] initWithNibName:@"TargetView" bundle:nil];

    vc.object=yourObject; //Create a p

    [self.navigationController pushViewController:vc animated:YES];

}

In your TargetView 在您的TargetView中

-(void)viewDidLoad{

   self.lbl.text=self.object.value;

}

You can make a notification and post notification with a object. 您可以发出通知,也可以通过对象发布通知。 The object what you need to send to second Controller. 您需要发送给第二个控制器的对象。

try this ..... 尝试这个 .....

1.create a property in your target view controller . 1.在目标视图控制器中创建一个属性。

2. 2。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
      targetviewcontroller * obj = create object here .
      obj.property = dataToBeSent ;

      ---------------
}

then you will get your data by accessing property 然后您将通过访问属性来获取数据

暂无
暂无

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

相关问题 当我轻按任何集合视图单元格时(不点击最后一个单元格),如何移动另一个视图控制器? - How to move another view controller when i tapped any collection view cell (without taping last cell)? 单击表格单元格时,将变量值发送到下一个视图控制器 - Send variable value to next view controller when click a table cell 如何将选定的collectionview单元格发送到另一个视图控制器(ios)? - How to send a selected collectionview cell to another view controller (ios)? 当我单击leftViewcontroller单元格时,MMDrawerController导航到另一个视图控制器 - MMDrawerController navigating to another view controller when I click on the leftViewcontroller cell 单击另一个视图控制器中的按钮时实现原型单元 - implement prototype cell when I click a button in another view Controller iOS如何将选定的单元格值隔离到另一个视图控制器中 - iOS how to segue a selected cell value into another view controller 如何将单元格中的第三个值传递给另一个表视图控制器 - How to pass a third value in a cell to another table view controller 在快速的iOS 8中,当单击一个单元格时,如何获取它以打开另一个视图控制器? - In swift iOS 8 when a cell is clicked, how do I get it to open another view controller? 如果表行中的某些值已更新,如何切换到另一个视图控制器? - How to switch to another view controller if some value in a table row is updated? 如何将信息从一个视图控制器中的表视图单元传递到另一视图控制器? - How do I pass information from a table view cell in one view controller to another view controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM