[英]pass data from tableview controller to details table view controller
I have the following code. 我有以下代码。 I want to display the data that is selected. 我想显示所选的数据。 However, below code is display every post in database. 但是,下面的代码显示数据库中的每个帖子。 I would like it to display just the one that is selected. 我希望它仅显示所选的那个。 How can i do that? 我怎样才能做到这一点?
Post Table View Controller: 表后视图控制器:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (![self objectAtIndexPath:indexPath]) {
// Load More Cell
[self loadNextPage];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.objects.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = @"Cell";
UserFeedTableViewCell *cell = (UserFeedTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UserFeedTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (object) {
cell.postView.text = [object objectForKey:@"post"];
// PFQTVC will take care of asynchronously downloading files, but will only load them when the tableview is not moving. If the data is there, let's load it right away.
}
return cell;
}
Details View Controller: 详细信息视图控制器:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = @"Cell1";
CommentsTableViewCell *cell = (CommentsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CommentsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (object) {
cell.detailsPost.text = [object objectForKey:@"post"];
}
return cell;
}
You should select a row in tableView:didSelectRowAtIndexPath 您应该在tableView:didSelectRowAtIndexPath中选择一行
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ {
// store relevant value in your text object
[self performSegueWithIdentifier:@"showSegue" sender:self];
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
} }
and the perform segue 和表演赛
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
DetailViewController *controller= [segue destinationViewController];
// set your text object here
controller.text = // your text object
}
HTH 高温超导
Create an object of the detail table view controller (on which you have to display the data) in the table view controller (from which data is sent), in the following way, 通过以下方式在表视图控制器中(从中发送数据)创建详细信息表视图控制器的对象(必须在其上显示数据),
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { DetailTableViewController *objNext = (DetailTableViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"detailVC"]; objNext.strLink=[[feeds objectAtIndex:indexPath.row] valueForKey:@"link"]; [self.navigationController pushViewController:objNext animated:YES]; }
Pass the data which you want to pass on row select, 在行选择中传递您要传递的数据,
Here are some links which show how to pass data from one view controller to another, some of them are from stack overflow itself. 这里有一些链接显示了如何将数据从一个视图控制器传递到另一个视图控制器,其中一些来自堆栈溢出本身。
Passing Data between View Controllers 在视图控制器之间传递数据
ios Pass data between navigation controller ios在导航控制器之间传递数据
https://teamtreehouse.com/community/how-to-pass-data-between-two-view-controllers-when-you-have-tab-bar-and-navigation-controller-in-between https://teamtreehouse.com/community/how-to-pass-data-between-two-view-controllers-when-you-have-tab-bar-and-navigation-controller-in-between
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.