[英]How to send some value to another view controller when i select cell?
I have two View Controllers: MainScreenViewController
and TargetScreenViewController
; 我有两个视图控制器: MainScreenViewController
和TargetScreenViewController
;
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: 在TargetView中:
- (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.