0

我正在创建一个应用程序,在其中将我的注册用户可视化到 Parse.com 的数据浏览器(在 TableView 控制器中),并将所选单元格的数据步进到新的视图控制器中。

我的问题是我无法在新的视图控制器中查看图像,您能告诉我该怎么做吗?我正在尝试了解和调查各种论坛上的 argormento,但在论坛上找不到答案,Parse 已经很长时间没有答案了。

这是我正在处理的代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {        if ([segue.identifier isEqualToString:@"Visual"]){

           NSIndexPath *indexPath = [self.Tork indexPathForSelectedRow];
           PFObject *object = [self.objects objectAtIndex:indexPath.row];
           ViewController  *detailViewController = [segue destinationViewController];
           detailViewController.oggetto = object;  } }

表视图:

- (PFQuery *)queryForTable {
    PFQuery *query = [PFQuery queryWithClassName:@"_User"];
    [query whereKeyExists:@"username"];
    [query whereKeyExists:@"picture"];
    [query whereKeyExists:@"email"];

    // If no objects are loaded in memory, we look to the cache first to fill the table
    // and then subsequently do a query against the network.
    if ([self.objects count] == 0) {
        query.cachePolicy = kPFCachePolicyCacheThenNetwork; }

    [query orderByAscending:@"username"];        
    return query;    }




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

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

    // Configure the cell
    cell.textLabel.text = [object objectForKey:@"username"];
    cell.detailTextLabel.text =  [object objectForKey:@"email"]];
   cell.imageView.image = [UIImage imageNamed:@"none.png"];


    PFFile *file = [object objectForKey:@"picture"];
    [file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        cell.imageView.image =[UIImage imageWithData:data];

    }];

    return cell;
}
4

1 回答 1

0

感谢您的回复:) ...问题似乎已解决..我更改了以下内容为此做准备,现在可以使用了!你怎么看?你看起来合适吗?直到现在还没有导致我的应用程序崩溃。

PfQueryTableViewController.m

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"Visual"]){

        NSIndexPath *indexPath = [self.tavola indexPathForSelectedRow];
        PFObject *object = [self.objects objectAtIndex:indexPath.row];
        PFFile *file = [self.objects objectAtIndex:indexPath.row ];

        ViewController  *detailViewController = [segue destinationViewController];
        detailViewController.oggetto = object;
        detailViewController.file = file;
    }
}

细节视图控制器.m

 - (void)viewDidLoad
{
    [super viewDidLoad];
    self.nome.text = [oggetto objectForKey:@"username"];
    self.email.text = [oggetto objectForKey:@"email"];

    PFFile *imageFile = [oggetto objectForKey:@"foto"];
    [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        self.image.image =[UIImage imageWithData:data];                       
    }];   
}

现在我遇到了这部分代码的问题,我正在添加一个带有显示的搜索栏。该代码没有返回错误,但在开始搜索时没有显示任何结果。这是代码,你有想法吗?

- (void)callbackLoadObjectsFromParse:(NSArray *)result error:(NSError *)error {
    if (!error) {
        NSLog(@"Successfully fetched %d entries", result.count);

         [self.searchResults addObjectsFromArray: result];

    } else {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }

}

- (void)filterResults:(NSString *)searchTerm {

    [self.searchResults removeAllObjects];

    PFQuery *query = [PFQuery queryWithClassName: @"_User"];
    [query whereKeyExists:@"username"];  //this is based on whatever query you are trying to accomplish
    [query whereKeyExists:@"foto"]; //this is based on whatever query you are trying to accomplish
    [query whereKeyExists:@"email"];
    query.cachePolicy = kPFCachePolicyNetworkOnly;
    query.limit = 50;
    [query findObjectsInBackgroundWithTarget:self selector:@selector(callbackLoadObjectsFromParse:error:)];


}


- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:  (NSString *)searchString {
    [self filterResults:searchString];
    return YES;
}

日志告诉我这一点,但我没有在设备上显示结果:(

AssertMacros:queueEntry,文件:/SourceCache/IOKitUser/IOKitUser-920.1.11/hid.subproj/IOHIDEventQueue.c,行:512 09/13/2013 01:34:50.537 Unipot v.02 [412:60 b] 成功获取9 个条目

于 2013-09-12T23:45:49.997 回答