URL から json データを取得しています: http://api.kivaws.org/v1/loans/search.json?status=fundraisingsecondviewcontroller
画面で取得していますが、データをスルーに直接送信する必要があります。のボタンをクリックsegue
して my にバインドせずに。firstviewcontroller
firstviewcontroller
#import "ViewController.h"
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define kLatestKivaLoansURL [NSURL URLWithString:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising"]
@implementation ViewController
@synthesize textinput;
- (IBAction)loadData {
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:
kLatestKivaLoansURL];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:data waitUntilDone:YES];
});
}
- (void)fetchedData:(NSData *)responseData {
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSArray* latestLoans = [json objectForKey:@"loans"]; //2
NSLog(@"loans: %@", latestLoans); //3
[textinput resignFirstResponder];
if ([textinput.text isEqualToString:@""])
{
display.text = @"Enter The Value";
}else{
if ([textinput.text isEqualToString:@"loans"])
{
NSDictionary* loans = [latestLoans objectAtIndex:0];
NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:
lblWHO.text = [loans objectForKey:@"name" ],
lblActivtiy.text = [loans objectForKey:@"activity"],nil];
lblLoan.text = [(NSDictionary*)[loans objectForKey:@"location"]
objectForKey:@"country"], nil;
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:info
options:NSJSONWritingPrettyPrinted error:&error];
}
}
}
次のように、 myfirstviewcontroller
にバインドされたデータを に渡します。segue
secondviewcontroller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowCustDetail"])
{
self.showact = Activity.text;
self.showname = Name1.text;
self.showcount = Country.text;
CustViewController *cv = [segue destinationViewController];
cv.showact = self.showact;
cv.showname = self.showname;
cv.showcount = self.showcount;
}
}
しかし、このデータをfirstviewcontrollerに入れずに、destinationviewcontrollerに直接バインドする必要があります
#import "CustViewController.h"
@interface CustViewController ()
@end
@implementation CustViewController
@synthesize Name1;
@synthesize showname;
@synthesize showact;
@synthesize showcount;
@synthesize Name2;
@synthesize Name3;
- (void)viewDidLoad
{
[super viewDidLoad];
Name1.text = self.showact;
Name2.text = self.showname;
Name3.text = self.showcount;
Name4.text = self.showstat;
Name5.text = self.showsect;
}
@end
私をあなたたちとつないでくれてありがとう。解決策が得られれば便利です。