Domanda

In a UITableViewController I try to do this:

In interface:

@property (nonatomic, strong) NSMutableArray *tickets;

In implementation

for(NSString *t in [SharedPreferences getTickets]){

    [[TicketListManager sharedManager] ticket:^(Ticket *sc) {

       [self.tickets addObject:sc];
       [self.tableView reloadData];

        NSLog(@"ticket %d", self.tickets.count);
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        NSLog(@"error");
    } ticket:ticketId];
}

While all objects are loaded successfully (I logged them), the count of tickets is always 0, so my table wont update. Any ideas why the objects are not saved to the array? I am on xcode 5, iOS7 and restkit 0.20.3

È stato utile?

Soluzione

Most likely self.tickets is not initialised. Set:

self.tickets = [NSMutableArray array];

When you create the controller.

Aside: your method ticket:failure:ticket: isn't very clear and would be better as getTicketWithId:success:failure:.

Another aside: be careful with starting network connections in a loop as you could flood the network. You may want to limit the concurrent connection by editing the queue of the http client.

Altri suggerimenti

Try this may be this work -

for(NSString *t in [SharedPreferences getTickets]){

        [[TicketListManager sharedManager] ticket:^(Ticket *sc) {

            [self.tickets addObject:sc];
            [self performSelectorOnMainThread:@selector(reloadTableData) withObject:Nil waitUntilDone:TRUE];

            NSLog(@"ticket %d", self.tickets.count);
        } failure:^(RKObjectRequestOperation *operation, NSError *error) {
            NSLog(@"error");
        } ticket:ticketId];
    }

-(void)reloadTableData{
    [self.tableView reloadData];
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top