Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.72 KB | None | 0 0
  1. @interface PSAData : NSObject
  2.  
  3. @property (nonatomic, strong) NSString *firstname;
  4. @property (nonatomic, strong) NSString *lastname;
  5.  
  6. - (void)loadWithDictionary:(NSDictionary *)dict;
  7.  
  8. @end
  9.  
  10. @implementation PSAData
  11.  
  12. - (void)loadWithDictionary:(NSDictionary *)dict
  13. {
  14. self.firstname=[dict objectForKey:@"firstname"];
  15. self.lastname=[dict objectForKey:@"lastname"];
  16. }
  17.  
  18. #import <UIKit/UIKit.h>
  19. #import "PSAData.h"
  20. #import "NetworkConnectivityClass.h"
  21. @interface PSATableViewCell : UITableViewCell
  22.  
  23. @property (nonatomic) NetworkConnectivityClass *networkConnectivityClassInstance;
  24.  
  25. -(void)loadWithData:(PSAData *)psaData;
  26. @end
  27.  
  28. @interface PSATableViewCell ()
  29. @property (strong, nonatomic) IBOutlet UILabel *firstnameLbl;
  30. @property (strong, nonatomic) IBOutlet UILabel *lastnameLbl;
  31.  
  32.  
  33. @end
  34.  
  35. @implementation PSATableViewCell
  36.  
  37. - (void)awakeFromNib {
  38. [super awakeFromNib];
  39. // Initialization code
  40. }
  41.  
  42. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  43. [super setSelected:selected animated:animated];
  44.  
  45.  
  46. }
  47.  
  48. -(void)loadWithData:(PSAData *)psaData
  49. {
  50. [self methodSetupText:psaData];
  51. }
  52.  
  53. -(void)methodSetupText:(PSAData *)psaData
  54. {
  55. self.firstnameLbl.text=psaData.firstname;
  56. self.lastnameLbl.text=psaData.lastname;
  57.  
  58. }
  59. @end
  60.  
  61. - (void)viewDidLoad {
  62. [super viewDidLoad];
  63.  
  64.  
  65. // NSMutableArray *selectedArray=[[NSMutableArray alloc]init];
  66.  
  67. tableView1.dataSource =self;
  68. tableView1.delegate=self;
  69. tableView2.dataSource=self;
  70. tableView2.delegate=self;
  71.  
  72. //initializing arrays for get selected values
  73. self.selectedCells=[NSMutableArray array];
  74. self.selectedPSAData=[NSMutableArray array];
  75.  
  76. //loading web resonse data
  77. self.loadedPSAData=[[NSMutableArray alloc]init];
  78.  
  79. NetworkConnectivityClass *networkConnectivityClassInstance = [NetworkConnectivityClass new];
  80.  
  81. __weak PersonnelViewController *weakVersionOfSelf=self;
  82.  
  83. [networkConnectivityClassInstance methodReturnTableViewMessages:^(NSMutableArray *returnedArrayWithMessages)
  84. {
  85. weakVersionOfSelf.loadedPSAData=returnedArrayWithMessages;
  86. [weakVersionOfSelf.tableView1 reloadData];
  87.  
  88. }];
  89. //register left side tableview cell (Assigned tableview1)
  90. [self.tableView1 registerNib:[UINib nibWithNibName:@"PSATableViewCell" bundle:nil] forCellReuseIdentifier:@"PSATableViewCell"];
  91.  
  92. }
  93.  
  94. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  95.  
  96. if(tableView ==self.tableView1)
  97. {
  98. return 1;
  99. }
  100. return 1;
  101. }
  102.  
  103. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  104.  
  105. if(tableView==self.tableView1)
  106. {
  107.  
  108. return self.loadedPSAData.count;
  109.  
  110. }
  111. return self.loadedPSAData.count;
  112. }
  113.  
  114. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  115.  
  116.  
  117. //loading table data into cell tableview1 and tableview2
  118. static NSString *cellIdentifier=@"PSATableViewCell";
  119.  
  120. PSATableViewCell *cell=[tableView1 dequeueReusableCellWithIdentifier:cellIdentifier];
  121.  
  122.  
  123. if (cell==nil) {
  124.  
  125. cell=[[PSATableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PSATableViewCell"];
  126. }
  127.  
  128.  
  129.  
  130. //tableview2 implementation
  131. static NSString *cellIdentifier2=@"PSSITableViewCell";
  132.  
  133. PSSITableViewCell *cell2=[tableView2 dequeueReusableCellWithIdentifier:cellIdentifier2];
  134.  
  135. if (cell2==nil) {
  136. cell2=[[PSSITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PSSITableViewCell"];
  137. }
  138. cell.accessoryType = ([self isRowSelectedOnTableView:tableView1 atIndexPath:indexPath]) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
  139.  
  140. if(tableView == self.tableView1)
  141. {
  142. [cell loadWithData:[self.loadedPSAData objectAtIndex:[indexPath row]]];
  143. }
  144. else if(tableView == self.tableView2)
  145. {
  146. [cell2 loadWithDataS2:[self.loadedPSAData objectAtIndex:[indexPath row]]];
  147. return cell2;
  148. }
  149.  
  150. return cell;
  151. }
  152.  
  153. - (void)tableView:(UITableView *)tableView
  154. didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  155.  
  156. NSString *psaData =[self.loadedPSAData objectAtIndex:indexPath.row];
  157. PSATableViewCell *cell=[tableView1 cellForRowAtIndexPath:indexPath];
  158.  
  159.  
  160. NSString *sampleAH =[self.selectedPSAData description];
  161.  
  162. if([self isRowSelectedOnTableView:tableView1 atIndexPath:indexPath])
  163. {
  164. [self.selectedCells removeObject:indexPath];
  165. [self.selectedPSAData removeObject:psaData];
  166.  
  167. cell.accessoryType =UITableViewCellAccessoryNone;
  168. }
  169. else{
  170. [self.selectedCells addObject:indexPath];
  171. [self.selectedPSAData addObject:psaData];
  172.  
  173. cell.accessoryType =UITableViewCellAccessoryCheckmark;
  174.  
  175. }
  176.  
  177. NSLog(@"%@", self.selectedPSAData);
  178.  
  179.  
  180. sampleArrayholder.text=[NSString stringWithFormat:@"%@", sampleAH];
  181.  
  182. }
  183.  
  184. -(BOOL)isRowSelectedOnTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath
  185. {
  186. return ([self.selectedCells containsObject:indexPath]) ? YES : NO;
  187. }
  188.  
  189. #import <Foundation/Foundation.h>
  190. #import <UIKit/UIKit.h>
  191. #import "WorksitenameList.h"
  192.  
  193. @interface NetworkConnectivityClass : NSObject
  194.  
  195. -(void)methodLogin:(NSString *)stringToLogin withUserName:(NSString *)stringUsername withPassword:(NSString *)stringPassword completion:(void(^)(NSDictionary *))completion;
  196.  
  197.  
  198. -(void)methodReturnTableViewMessages:(void (^)(NSMutableArray *))completion;
  199.  
  200.  
  201. -(NSURLSessionTaskState)methodCheckIfSessionIsRunning;
  202.  
  203. -(void)methodCancelNetworkRequest;
  204.  
  205. -(void)methodReturnTableViewMessages:(void (^)(NSMutableArray *))completion
  206. {
  207. dispatch_queue_t queueForJSON = dispatch_queue_create("queueForJSON", NULL);
  208. dispatch_async(queueForJSON, ^{
  209. NSString *filePath = [[NSBundle mainBundle] pathForResource:@"PSAData" ofType:@"json"];
  210.  
  211. NSError *error = nil;
  212.  
  213. NSData *rawData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error];
  214.  
  215. id JSONData = [NSJSONSerialization JSONObjectWithData:rawData options:NSJSONReadingAllowFragments error:&error];
  216.  
  217. NSMutableArray *loadedPSAData = [NSMutableArray new];
  218. [loadedPSAData removeAllObjects];
  219.  
  220. if([JSONData isKindOfClass:[NSDictionary class]])
  221. {
  222. NSArray *loadedArray=[JSONData objectForKey:@"records"];
  223. if([loadedArray isKindOfClass:[NSArray class]])
  224. {
  225. for(NSDictionary *psaDict in loadedArray)
  226. {
  227. PSAData *psaData=[[PSAData alloc]init];
  228. [psaData loadWithDictionary:psaDict];
  229. [loadedPSAData addObject:psaData];
  230. }
  231.  
  232. }
  233. }
  234. dispatch_async(dispatch_get_main_queue(), ^{
  235. completion(loadedPSAData);
  236. NSLog(@"test: %@", loadedPSAData);
  237. });
  238. });
  239.  
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement