简体   繁体   English

将数据从tableview控制器传递到明细表view控制器

[英]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.

相关问题 无法将数据从 tableview 传递到视图控制器 - unable to pass data from tableview to view controller 将数据从tableview控制器传递到视图控制器,但它显示为null - pass data from tableview controller to view controller, but it appears null 将数据从表视图传递到视图控制器 - Pass data from table view to view controller 如何将视图 controller 中的数据传递到表视图 controller? - How to pass the data from view controller to the table view controller? 在Swift中的选项卡栏中将数据从TableView传递到View Controller - Pass data from tableview to view controller in tab bar in Swift 将数据从tableview传递到Swift中的选项卡栏视图控制器。 - Pass data from tableview to tab bar view controller in Swift. 如何将解析数据从TableView传递到详细信息视图控制器? - How to pass parse data from tableview to detail view controller? Swift,如何将 tableview 数据传递给视图控制器? - Swift, how to pass tableview data to view controller? 在同一视图 controller 中将数据从集合视图传递到表视图: - pass data from collection view to table view in the same view controller: 如何将CloudKit记录数据从“ TableView-Controller B”传递到“ View-Controller C”? - How to pass the CloudKit records data from “TableView-Controller B” to “View-Controller C”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM