在 tableview (iOS) 中显示来自 parse.com 的数组 [英] Display array from parse.com in tableview (iOS)

查看:13
本文介绍了在 tableview (iOS) 中显示来自 parse.com 的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的表视图中显示一个数组,该数组位于 parse.com 上的数据库中我可以显示数组中的第一项,但不能显示其余项.

I am tying to display in my table view an array that is on a database on parse.com I can display the first item in the array, but not the rest.

- (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];
    }   
    _ListArray = [object objectForKey:@"content"];
    NSLog(@"OBJECT = %@",_ListArray);
    NSString *cellValue = [NSString stringWithFormat:@"%@", [_ListArray objectAtIndex:indexPath.row]];

    cell.textLabel.text = cellValue;

    if(refresh <counter)
    {
        NSString *br = @"<br>";
        List = [NSString stringWithFormat:@"%@%@%@", List, br, cell.textLabel.text];
        NSLog(@"%@",List);
        refresh ++;
    }       
    cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}

如果我尝试使用:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_ListArray count];
}

我在桌子上什么都没有.

I get nothing in the table.

编辑更新:

确实删除了 self.ListArray 并使用了 _ListArray.

did remove the self.ListArray and going with _ListArray.

在h文件中:

NSMutableArray *ListArray;
...
@property (retain, atomic) NSMutableArray *ListArray;

然后在 m 文件中:

@synthesize ListArray = _ListArray;

关于:

self.ListArray = [object objectForKey:@"content"];

对象是PFObject.

the object is the PFObject.

我有 queryForTable,我从解析中获取数据.

i have queryForTable where i get the data from parse.

- (PFQuery *)queryForTable {

    PFQuery *query = [PFQuery queryWithClassName:@"List"];
    [query whereKey:@"user" equalTo:[PFUser currentUser]]; // user
    [query whereKey:@"objectId" equalTo:[theListID objectId]]; // the specific list
    counter =[query countObjects];
    NSLog(@"%d",counter);

    // If Pull To Refresh is enabled, query against the network by default.
    if (self.pullToRefreshEnabled) {
        query.cachePolicy = kPFCachePolicyNetworkOnly;
    }

    // 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 orderByDescending:@"createdAt"];

    return query;

}

然后到 objectForKey:@"content"];content 是我的类中解析的列的名称所以我需要说明我想从类中获取什么对象,那就是名为content"的数组列

And to the objectForKey:@"content"]; content is the name of the column in my class on parse so i need to say what object from the class i want to get, and that is the array column named "content"

日志,(当 NSLog 在阵列上处于活动状态时.

The logg, (when the NSLog is active on the array.

Inköpslista[7856:12e03] Warning: A long-running Parse operation is being executed on the main thread. 
 Break on warnParseOperationOnMainThread() to debug.
2013-10-21 14:23:31.008 Inköpslista[7856:12e03] 1
2013-10-21 14:23:31.017 Inköpslista[7856:12e03] OBJECT = (
    "BrU00f6d",
    Anka,
    Boll,
    Sko
)
2013-10-21 14:23:31.017 Inköpslista[7856:12e03] <html><body><br>Bröd
2013-10-21 14:23:31.545 Inköpslista[7856:12e03] OBJECT = (
    "BrU00f6d",
    Anka,
    Boll,
    Sko
) 

推荐答案

得到它的工作,确实把数组放在我从解析中获取数据,然后只调用

Got it to work, did put the array were i get the data from parse, and then only call

cell.textLabel.text = [_ListArray objectAtIndex:indexPath.row];

然后我可以使用:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_ListArray count];
}

这篇关于在 tableview (iOS) 中显示来自 parse.com 的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆