iOS8SelfSizingCells
iOS8SelfSizingCells copied to clipboard
怎样可以在一个block里addobject to dataSource
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]; }