4

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;
}

If I try to use:

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

I get nothing in the table.

edit update:

did remove the self.ListArray and going with _ListArray.

in the h file:

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

and then in m file:

@synthesize ListArray = _ListArray;

regarding the:

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

the object is the PFObject.

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;

}

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"

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 = (
    "Br\U00f6d",
    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 = (
    "Br\U00f6d",
    Anka,
    Boll,
    Sko
) 
5
  • Please check what value comes in self.ListArray when you reload data Commented Oct 21, 2013 at 13:04
  • How is self.ListArray created? Commented Oct 21, 2013 at 13:09
  • In storyboard, are you set the identifier as @"Cell"? Commented Oct 21, 2013 at 13:09
  • What is the purpose of self.ListArray = [object objectForKey:@"content"]; ? If you're using the parse provided table view controller you just need to configure the cell for the passed object... Commented Oct 21, 2013 at 13:10
  • Did edit the post for more info. and in the storyboard the identifier is "Cell". Commented Oct 21, 2013 at 13:35

1 Answer 1

1

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];

and then i can use:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_ListArray count];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.