Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @interface PSAData : NSObject
- @property (nonatomic, strong) NSString *firstname;
- @property (nonatomic, strong) NSString *lastname;
- - (void)loadWithDictionary:(NSDictionary *)dict;
- @end
- @implementation PSAData
- - (void)loadWithDictionary:(NSDictionary *)dict
- {
- self.firstname=[dict objectForKey:@"firstname"];
- self.lastname=[dict objectForKey:@"lastname"];
- }
- #import <UIKit/UIKit.h>
- #import "PSAData.h"
- #import "NetworkConnectivityClass.h"
- @interface PSATableViewCell : UITableViewCell
- @property (nonatomic) NetworkConnectivityClass *networkConnectivityClassInstance;
- -(void)loadWithData:(PSAData *)psaData;
- @end
- @interface PSATableViewCell ()
- @property (strong, nonatomic) IBOutlet UILabel *firstnameLbl;
- @property (strong, nonatomic) IBOutlet UILabel *lastnameLbl;
- @end
- @implementation PSATableViewCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- }
- -(void)loadWithData:(PSAData *)psaData
- {
- [self methodSetupText:psaData];
- }
- -(void)methodSetupText:(PSAData *)psaData
- {
- self.firstnameLbl.text=psaData.firstname;
- self.lastnameLbl.text=psaData.lastname;
- }
- @end
- - (void)viewDidLoad {
- [super viewDidLoad];
- // NSMutableArray *selectedArray=[[NSMutableArray alloc]init];
- tableView1.dataSource =self;
- tableView1.delegate=self;
- tableView2.dataSource=self;
- tableView2.delegate=self;
- //initializing arrays for get selected values
- self.selectedCells=[NSMutableArray array];
- self.selectedPSAData=[NSMutableArray array];
- //loading web resonse data
- self.loadedPSAData=[[NSMutableArray alloc]init];
- NetworkConnectivityClass *networkConnectivityClassInstance = [NetworkConnectivityClass new];
- __weak PersonnelViewController *weakVersionOfSelf=self;
- [networkConnectivityClassInstance methodReturnTableViewMessages:^(NSMutableArray *returnedArrayWithMessages)
- {
- weakVersionOfSelf.loadedPSAData=returnedArrayWithMessages;
- [weakVersionOfSelf.tableView1 reloadData];
- }];
- //register left side tableview cell (Assigned tableview1)
- [self.tableView1 registerNib:[UINib nibWithNibName:@"PSATableViewCell" bundle:nil] forCellReuseIdentifier:@"PSATableViewCell"];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- if(tableView ==self.tableView1)
- {
- return 1;
- }
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if(tableView==self.tableView1)
- {
- return self.loadedPSAData.count;
- }
- return self.loadedPSAData.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- //loading table data into cell tableview1 and tableview2
- static NSString *cellIdentifier=@"PSATableViewCell";
- PSATableViewCell *cell=[tableView1 dequeueReusableCellWithIdentifier:cellIdentifier];
- if (cell==nil) {
- cell=[[PSATableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PSATableViewCell"];
- }
- //tableview2 implementation
- static NSString *cellIdentifier2=@"PSSITableViewCell";
- PSSITableViewCell *cell2=[tableView2 dequeueReusableCellWithIdentifier:cellIdentifier2];
- if (cell2==nil) {
- cell2=[[PSSITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PSSITableViewCell"];
- }
- cell.accessoryType = ([self isRowSelectedOnTableView:tableView1 atIndexPath:indexPath]) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
- if(tableView == self.tableView1)
- {
- [cell loadWithData:[self.loadedPSAData objectAtIndex:[indexPath row]]];
- }
- else if(tableView == self.tableView2)
- {
- [cell2 loadWithDataS2:[self.loadedPSAData objectAtIndex:[indexPath row]]];
- return cell2;
- }
- return cell;
- }
- - (void)tableView:(UITableView *)tableView
- didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- NSString *psaData =[self.loadedPSAData objectAtIndex:indexPath.row];
- PSATableViewCell *cell=[tableView1 cellForRowAtIndexPath:indexPath];
- NSString *sampleAH =[self.selectedPSAData description];
- if([self isRowSelectedOnTableView:tableView1 atIndexPath:indexPath])
- {
- [self.selectedCells removeObject:indexPath];
- [self.selectedPSAData removeObject:psaData];
- cell.accessoryType =UITableViewCellAccessoryNone;
- }
- else{
- [self.selectedCells addObject:indexPath];
- [self.selectedPSAData addObject:psaData];
- cell.accessoryType =UITableViewCellAccessoryCheckmark;
- }
- NSLog(@"%@", self.selectedPSAData);
- sampleArrayholder.text=[NSString stringWithFormat:@"%@", sampleAH];
- }
- -(BOOL)isRowSelectedOnTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath
- {
- return ([self.selectedCells containsObject:indexPath]) ? YES : NO;
- }
- #import <Foundation/Foundation.h>
- #import <UIKit/UIKit.h>
- #import "WorksitenameList.h"
- @interface NetworkConnectivityClass : NSObject
- -(void)methodLogin:(NSString *)stringToLogin withUserName:(NSString *)stringUsername withPassword:(NSString *)stringPassword completion:(void(^)(NSDictionary *))completion;
- -(void)methodReturnTableViewMessages:(void (^)(NSMutableArray *))completion;
- -(NSURLSessionTaskState)methodCheckIfSessionIsRunning;
- -(void)methodCancelNetworkRequest;
- -(void)methodReturnTableViewMessages:(void (^)(NSMutableArray *))completion
- {
- dispatch_queue_t queueForJSON = dispatch_queue_create("queueForJSON", NULL);
- dispatch_async(queueForJSON, ^{
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"PSAData" ofType:@"json"];
- NSError *error = nil;
- NSData *rawData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error];
- id JSONData = [NSJSONSerialization JSONObjectWithData:rawData options:NSJSONReadingAllowFragments error:&error];
- NSMutableArray *loadedPSAData = [NSMutableArray new];
- [loadedPSAData removeAllObjects];
- if([JSONData isKindOfClass:[NSDictionary class]])
- {
- NSArray *loadedArray=[JSONData objectForKey:@"records"];
- if([loadedArray isKindOfClass:[NSArray class]])
- {
- for(NSDictionary *psaDict in loadedArray)
- {
- PSAData *psaData=[[PSAData alloc]init];
- [psaData loadWithDictionary:psaDict];
- [loadedPSAData addObject:psaData];
- }
- }
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- completion(loadedPSAData);
- NSLog(@"test: %@", loadedPSAData);
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement