gpt4 book ai didi

ios - tableview segue 到另一个 View Controller

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:02:38 26 4
gpt4 key购买 nike

我是编程新手,可能被一个简单的问题挂断了。我在我的 TableView 中为我的数组使用解析。选择该行后,我想转到另一个 View Controller 上的搜索栏。 segue 工作正常,tableview 工作正常,但我似乎无法让 objectId 通过。

#import "bookmarkViewController.h"
#import "Parse/Parse.h"
#import <ParseUI/ParseUI.h>
#import "ViewController.h"

@implementation bookmarkViewController

@synthesize postArray;


#pragma mark - View lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];

[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self
action:@selector(refreshButtonHandler:)]];

}

- (void)viewWillAppear:(BOOL)animated
{
if ([PFUser currentUser])
[self refreshButtonHandler:nil];
}

#pragma mark - Button handlers

- (void)refreshButtonHandler:(id)sender
{
//Create query for all Post object by the current user
PFQuery *postQuery = [PFQuery queryWithClassName:@"Post"];
[postQuery whereKey:@"author" equalTo:[PFUser currentUser]];

// Run the query
[postQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
//Save results and update the table
postArray = objects;
[self.tableView reloadData];
}
}];
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section
{
// Return the number of rows in the section.
return postArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}

// Configure the cell with the textContent of the Post as the cell's text label
PFObject *post = [postArray objectAtIndex:indexPath.row];
[cell.textLabel setText:[post objectForKey:@"textContent"]];

return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath{
NSLog(@"cell tapped");
PFObject *post = [postArray objectAtIndex:indexPath.row];
NSLog(@"%@", post.objectId);
[self performSegueWithIdentifier:@"searchBookmark" sender:self];



}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
ViewController *vc = [segue destinationViewController];

vc.labelText = post.objectId;
}
}


@end

在 vc.label.text 中,我总是使用未声明的标识符“post”,但我似乎无法弄清楚如何识别它。就是在上面的方法中。

NSLogs 正确回复 16:17:27.513 [App] 单元格被窃听 [应用] cgdVY7Eu9h

最佳答案

将您的 didSelectRowAtIndexPath 和 prepareForSegue 更改为:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath* )indexPath{
[self performSegueWithIdentifier:@"searchBookmark" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

NSLog(@"cell tapped");
PFObject *post = [postArray objectAtIndex:indexPath.row];
NSLog(@"%@", post.objectId);
ViewController *vc = [segue destinationViewController];

vc.labelText = post.objectId;
}
}

关于ios - tableview segue 到另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27238999/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com