Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法获取子类UITableViewCells以显示成功查询的分析对象中的数据_Ios_Objective C_Cocoa Touch_Ios7_Parse Platform - Fatal编程技术网

Ios 无法获取子类UITableViewCells以显示成功查询的分析对象中的数据

Ios 无法获取子类UITableViewCells以显示成功查询的分析对象中的数据,ios,objective-c,cocoa-touch,ios7,parse-platform,Ios,Objective C,Cocoa Touch,Ios7,Parse Platform,这个问题已经得到了成功的回答;感谢您访问jsksma2 我无法获取数据来填充TableView中的行,即使我正确地获取了数据,并且可以对TableView进行硬编码以显示静态数量的虚拟文本。我有一种预感,我的问题与子类UITableViewCells的initWithStyle与initWithCoder有关 在名为“GiveItemStableViewController”的UITableViewController的子类中,在viewDidLoad期间,我正在查询每个名为“PFGiveIte

这个问题已经得到了成功的回答;感谢您访问jsksma2

我无法获取数据来填充TableView中的行,即使我正确地获取了数据,并且可以对TableView进行硬编码以显示静态数量的虚拟文本。我有一种预感,我的问题与子类UITableViewCells的initWithStyle与initWithCoder有关

在名为“GiveItemStableViewController”的UITableViewController的子类中,在viewDidLoad期间,我正在查询每个名为“PFGiveItem”的对象的解析。我把它们取回,并将它们添加到一个全局变量中,一个称为“myGiveItems”的可变数组。我把这些记录下来,然后我得到了我想要的东西,所以那个部分可以工作了

GiveItemsTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    PFQuery *query = [PFQuery queryWithClassName:@"giveItem"];
    [query whereKey:@"giver" equalTo:[PFUser currentUser]];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            self.myGiveItems = [[NSMutableArray alloc]init];
            for (PFObject *object in objects) {
                PFGiveItem *newGiveItem = [[PFGiveItem alloc]init];
                newGiveItem.giveItemName = object[@"giveItemTitle"];
                newGiveItem.giveItemImage = object[@"giveItemPhoto"];
                [self.myGiveItems addObject:newGiveItem];
            }
        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }

    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}


- (JFGiveItemCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellIdentifier = @"Cell";

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

    //    PFGiveItem *giveItem = self.myGiveItems[indexPath.row];
    //    cell.giveItemLabel.text = giveItem.giveItemName;
    cell.giveItemLabel.text = @"Test";
    return cell;
}
现在,我正尝试使用自定义TableViewCell(每个称为“GiveItemCell”)将这些giveItems中的每一个加载到TableView对象中

GiveItemCell.m

@implementation JFGiveItemCell



@synthesize giveItemImageView = _giveItemImageView;
@synthesize giveItemLabel = _giveItemLabel;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}
回到表视图控制器中,我为表视图返回一个部分。 当我为rowsin部分包含一个静态数字时,我可以将测试值输出到每个单元格。如果我执行下面的代码,我将得到一个带有标签为“Test”的单元格的tableView,正如即将到来的CellForRowatineXpath方法一样。因此,它可以用于该测试,但显然我希望动态加载适当的信息

GiveItemsTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    PFQuery *query = [PFQuery queryWithClassName:@"giveItem"];
    [query whereKey:@"giver" equalTo:[PFUser currentUser]];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            self.myGiveItems = [[NSMutableArray alloc]init];
            for (PFObject *object in objects) {
                PFGiveItem *newGiveItem = [[PFGiveItem alloc]init];
                newGiveItem.giveItemName = object[@"giveItemTitle"];
                newGiveItem.giveItemImage = object[@"giveItemPhoto"];
                [self.myGiveItems addObject:newGiveItem];
            }
        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }

    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}


- (JFGiveItemCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellIdentifier = @"Cell";

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

    //    PFGiveItem *giveItem = self.myGiveItems[indexPath.row];
    //    cell.giveItemLabel.text = giveItem.giveItemName;
    cell.giveItemLabel.text = @"Test";
    return cell;
}

有几个问题

numberOfRowsInSection应返回myGiveItems数组的大小

在异步加载完项后,需要通知表视图重新加载


您不需要实现节数,它默认为1。

看起来您忘记在块方法的回调中调用
[tableView reloadData]

- (void)viewDidLoad
{
    [super viewDidLoad];
    PFQuery *query = [PFQuery queryWithClassName:@"giveItem"];
    [query whereKey:@"giver" equalTo:[PFUser currentUser]];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            self.myGiveItems = [[NSMutableArray alloc]init];
            for (PFObject *object in objects) {
                PFGiveItem *newGiveItem = [[PFGiveItem alloc]init];
                newGiveItem.giveItemName = object[@"giveItemTitle"];
                newGiveItem.giveItemImage = object[@"giveItemPhoto"];
                [self.myGiveItems addObject:newGiveItem];
            }
            [self.tableView reloadData];
        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }

    }];
}
此外,我支持@CrimsonChris的说法,即您需要正确设置数据源方法:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  return self.myGiveItems.count
}

我使用“return4”只是想看看它在硬编码时是否有效,它确实有效。当我使用“return self.myGiveItems.count”时,表格单元格无法正确显示。您到底有什么问题?确切的问题是我无法使表格视图单元格与我想要的标签一起显示。事实上,当尝试动态加载标签文本和行数时(与硬编码占位符相反),我根本无法获得任何标签或正确的行数。