Closed deadislove closed 6 years ago
Hello,
I think prepareForSegue
is not a good place to run the network operation and get the async callback from the SDK. The code for what you are trying to achieve is correct, but you need to perform the scan operation either before the user triggers the change in View Controller or after.
Example: You can pass the required details to the destination view controller and then call the dynamo db operation in the view did load of the destination view controller and call reloadData
on callback.
Thanks, Rohan
@rohandubal Network operation? Does you mean the network operation center(NOC)? Can you tell me more about the network operation concept?
@rohandubal I try to use your idea, but it has same as problem. I find out the " [[dynamoDBObjectMapper scan:[Books class] expression:scanExpression]" can't keep running. It always jump to end point in the first time running.
My function code. ` -(NSMutableArray )ScanDB { NSMutableArray MustableArray = [[NSMutableArray alloc] init];
AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
AWSDynamoDBScanExpression *scanExpression = [AWSDynamoDBScanExpression new];
scanExpression.limit = @10;
[[dynamoDBObjectMapper scan:[Books class]
expression:scanExpression]
continueWithBlock:^id(AWSTask *task) {
if (task.error) {
NSLog(@"The request failed. Error: [%@]", task.error);
} else {
AWSDynamoDBPaginatedOutput *paginatedOutput = task.result;
for (Books *book in paginatedOutput.items) {
//Do something with book.
[MustableArray addObject:book._ISBN];
NSLog(@"Test!");
}
}
return nil;
}];
return MustableArray;
}`
My viewDidLoad code: `
(void)viewDidLoad {
SecondViewController second = [[SecondViewController alloc] init]; [self presentViewController:(SecondViewController )second animated:YES completion:nil]; } `
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.
How to pass the data array of the dynamodb scan function result with the segue method in Objective C?
My problem: I want to pass the AWS dynamodb scan function result from the view controllers file to another view controller files with segue methods? I think the segue methods are easy passing the data from the view controller files to another view controller file, but it is really not true.
Running my code process: Step1. Execute to read the second view controller.m file. Step2. Execute to go back the view controller.m file. Step3. Execute the if statement in the view controller.m file. Step4. Execute to go to the second view controller.m file. Step5. Execute to go back the view controller.m file. Step6. Execute the AWS dynamodb scan function, then return the null. Step7. Stop running.
View Controller.m files:
`- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"DetailPage"]) {
}`
Second View Controller.h file
`#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController { NSMutableArray AccessArray; NSString TestString; NSArray *StringArray; } //Second View Controller
//Access Data variable @property (strong, nonatomic) IBOutlet NSMutableArray AccessArray; @property (strong, nonatomic) IBOutlet NSArray StringArray; @property (retain, nonatomic) IBOutlet NSString *TestString;
@end`
Second view controller.m file
`#import "SecondViewController.h"
import "Books.h"
import <AWSCognito/AWSCognito.h>
@interface SecondViewController ()
@end
@implementation SecondViewController
@synthesize AccessArray,TestString,StringArray;
(void)viewDidLoad { [super viewDidLoad];
if (AccessArray.count!=0) { //int *iCount = AccessArray.count; [TestLabel setText:[NSString stringWithFormat:@"%li",AccessArray.count]]; } }`