문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top