I have problem with send array value to another class. I'm sure that it's obvious but I don't have any idea to do this.
I'll be glad for any example code.
Problem: class1 send text from searchBar to class2. In class2 I get a data from www[JSONModel] and generate an array. My problem is how to send value this array to class1 and make reloadData in tableView.
To send data from class1 to class2 I use delegate method [SearchTextDelegate] I tried to make next delegate to send data from class2 to class1 but it doesn't work.
Thanks in advance.
my class1.m:
#pragma mark - searchBar
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text {
self.mySearchText = [NSString stringWithFormat:@"%@", text];
NSLog(@"mySearchText: %@", self.mySearchText);
if (text != 0) {
APIClient *wskAPI = [[APIClient alloc]init];
wskAPI.delegate = self;
wskAPI.searchText = self.mySearchText;
[wskAPI createSearchString];
}
[self.tableView reloadData];
}
#pragma mark - Sample protocol delegate
-(void)searchProcessCompleted {
[self.tableView reloadData];
}
my class2.h [APIClient.h]:
#import <Foundation/Foundation.h>
#import "ITunesResultModel.h"
@protocol SearchTextDelegate <NSObject>
-(void)searchProcessCompleted;
@end
@interface APIClient : NSObject
@property (strong, nonatomic) id delegate;
@property (assign) id <SearchTextDelegate> stringDelegate;
@property (strong, nonatomic) NSString *searchString;
@property (strong, nonatomic) NSString *searchText;
@property (strong, nonatomic) ITunesResultModel *iTunesModel;
@property (strong, nonatomic) NSArray *resultArray;
-(void)createSearchString;
@end
my class2.m [APIClient.m]:
#import "APIClient.h"
#import "ITunesResultModel.h"
#import "JSONModelLib.h"
#import "class1.h"
@implementation APIClient
static NSString * const ITunesOnlineURLString = @"http://ift.tt/1CToUkG";
-(void)createSearchString {
NSLog(@"searchTextAPI: %@", self.searchText);
self.searchString = [NSString stringWithFormat:@"http://ift.tt/1j7O455", self.searchText];
//fetch the feed
self.iTunesModel = [[ITunesResultModel alloc] initFromURLWithString:self.searchString
completion:^(JSONModel *model, JSONModelError *err) {
//json fetched
//NSLog(@"result: %@", self.iTunesModel.results);
}];
}
@end
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire