Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎样可以在一个block里addobject to dataSource #7

Open
y9du opened this issue Mar 21, 2016 · 0 comments
Open

怎样可以在一个block里addobject to dataSource #7

y9du opened this issue Mar 21, 2016 · 0 comments

Comments

@y9du
Copy link

y9du commented Mar 21, 2016

Hi,

我想把AWS dynamoDB里的data 加入到dataSource里, 在block里可以添加,可是离开了block, dataSource就是空的了。我知道是因为block在return [dataSource copy]之后在complete,请问有什么解决方法吗?谢谢

  • (NSArray *)newDataSource {

    // __block NSMutableArray *dataSource = [[NSMutableArray alloc] init];

    __block NSMutableArray *dataSource = nil;
    dataSource = [[NSMutableArray alloc] init];

    NSDictionary *nameStyle = @{@"body":[UIFont fontWithName:@"HelveticaNeue" size:16],
    @"userName":[WPAttributedStyleAction styledActionWithAction:^{
    [[[UIAlertView alloc] initWithTitle:@"提示" message:@"点击了" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil] show];
    }],
    @"link": [UIColor blueColor]};

    listViewItem *listItem = [[listViewItem alloc] init];
    AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
    AWSDynamoDBScanExpression *scanExpression = [AWSDynamoDBScanExpression new];
    scanExpression.limit = @20;
    NSDate *today = [NSDate date];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd"];
    NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
    [timeFormat setDateFormat:@"HH:mm:00"];
    NSString *currentDate = [dateFormat stringFromDate:today];
    //NSString *currentTime = [timeFormat stringFromDate:today];
    [[dynamoDBObjectMapper scan:[Event class]
    expression:scanExpression]
    continueWithExecutor:[AWSExecutor mainThreadExecutor] withSuccessBlock:^id(AWSTask *task) {

            if (task.error) {
                NSLog(@"Scan Error: [%@]", task.error);
            }else
            {
                AWSDynamoDBPaginatedOutput *paginatedOutput = task.result;
                for (Event *item in paginatedOutput.items) {
                    if ([item.StartDate isEqualToString:currentDate]) {
                        listItem.likeCount = @"1125";
                        listItem.attrbutedComment = [item.Address attributedStringWithStyleBook:nameStyle];
                     [dataSource addObject:listItem];
                        NSLog(@"block dataSource array has %@",dataSource);
                    }
                }
    
            NSLog(@"Scan Succeeded");
            }
            return nil;}
      ];
    

    NSLog(@"dataSource array has %@",dataSource);
    return [dataSource copy];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant