我是編程新手,很可能掛了一個簡單的問題。我在我的tableview中使用解析我的數組。當選中該行時,我想繼續瀏覽另一個視圖控制器上的搜索欄。 segue工作正常,tableview工作正常,但我似乎無法得到objectId傳遞。tableview segue到另一個視圖控制器
#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我總是使用未聲明的標識符「後」,但我似乎無法找出得到它認可的方式。這是在上面的方法。
的NSLogs正確回答16:17:27.513 [應用]電池輸出 [應用] cgdVY7Eu9h
看到這些目的C](http://stackoverflow.com/a/22761617/3681880)或[Swift Answers](http://stackoverflow.com/a/31936367/3681880) – Suragch 2015-08-11 08:12:50