Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RootViewController code of SplitViewController
- //ContactTableView_iPad.h
- //
- // ContactTableView_iPad.h
- //
- #import <UIKit/UIKit.h>
- #import "LoadingViewClass.h"
- #import "CMPopTipView.h"
- #import "ContactContainer_iPad.h"
- @class DetailView_iPad;
- @class AppDelegate;
- @class ContactContainer_iPad;
- @interface ContactTableView_iPad : UITableViewController<NSXMLParserDelegate, CMPopTipViewDelegate>
- {
- AppDelegate *appdelegate;
- LoadingViewClass *loading;
- CMPopTipView *popTipView;
- UISplitViewController *splitViewController;
- NSArray *names,*id1;
- NSMutableArray *arrayOfCharacters;
- NSMutableDictionary *objectsForCharacters;
- NSMutableArray *arrayFinal;
- NSArray *vendorNameArray,*vendorIdArray;
- NSArray *clientNameArray,*clientIdArray;
- IBOutlet UISearchBar *serachBar;
- NSMutableArray *searchArray;
- NSMutableArray *dataArray;
- BOOL recordResults;
- NSMutableData *webData1;
- NSMutableString *soapResults;
- NSXMLParser *xmlParser;
- NSXMLParser *xmlParser1;
- NSString *reloadFlag;
- NSURLConnection *connection1;
- UIActivityIndicatorView *indicator;
- NSString *conId,*fName,*lName;
- NSString *serviceName,*serviceId;
- NSMutableArray *RecentContactNameArray2;
- NSMutableArray *RecentContactIdArray2;
- }
- @property (nonatomic, retain) IBOutlet DetailView_iPad *detailViewController;
- @property (nonatomic, retain) IBOutlet ContactTableView_iPad *tableViewController;
- @property(nonatomic,retain) IBOutlet UIButton *FilterButton;
- @property (nonatomic, retain) NSArray *names,*id1;
- @property (nonatomic, retain) NSArray *vendorNameArray,*vendorIdArray;
- @property (nonatomic, retain) NSArray *clientNameArray,*clientIdArray;
- @property (nonatomic, retain)NSMutableArray *RecentContactNameArray2;
- @property (nonatomic, retain)NSMutableArray *RecentContactIdArray2;
- @property (nonatomic, retain) NSMutableArray *arrayOfCharacters;
- @property (nonatomic, retain) NSMutableDictionary *objectsForCharacters;
- @property(nonatomic,retain) NSMutableData *webData;
- @property(nonatomic, retain) NSXMLParser *xmlParser;
- @property(nonatomic, retain) NSMutableString *firstName,*lastName,*sElmentString;
- @property(nonatomic,retain) IBOutlet UITableView *ContactTableview;
- @property(nonatomic,retain) NSMutableArray *conNameArray,*conIdArray;
- @property(nonatomic,retain) NSMutableArray *conNameArray1,*conIdArray1;
- @property(nonatomic,retain) NSMutableArray *conNameArray2,*conIdArray2;
- -(IBAction)HomeBtn:(id)sender;
- -(IBAction)backbtn:(id)sender;
- -(IBAction)RefreshBtn:(id)sender;
- - (void)setupIndexData;
- - (void)filterMethod;
- @end
- //ContactTableView_iPad.m
- //
- // ContactTableView_iPad.m
- // SPANPLAN
- //
- // Created by SPAN Technology on 9/30/13.
- // Copyright (c) 2013 SPAN TECHNOLOGY. All rights reserved.
- //
- #import "ContactTableView_iPad.h"
- #import "DetailView_iPad.h"
- #import "AppDelegate.h"
- #import "BackgroundLayer.h"
- #import "Reachability.h"
- #import "Errormsg.h"
- #import "AddContact.h"
- #import "MenuView.h"
- @interface ContactTableView_iPad ()
- @end
- @implementation ContactTableView_iPad
- @synthesize RecentContactIdArray2,RecentContactNameArray2;
- @synthesize names,id1;
- @synthesize vendorIdArray,vendorNameArray;
- @synthesize clientIdArray,clientNameArray;
- @synthesize arrayOfCharacters;
- @synthesize objectsForCharacters;
- @synthesize conIdArray1,conNameArray1,conIdArray2,conNameArray2,conIdArray,conNameArray;
- @synthesize webData;
- @synthesize xmlParser,firstName,sElmentString,lastName,FilterButton;
- @synthesize ContactTableview;
- @synthesize detailViewController;
- - (id)initWithStyle:(UITableViewStyle)style
- {
- self = [super initWithStyle:style];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- appdelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
- NSLog(@"viewDidLoad appdelegate.RecentNameArray1....... %@",appdelegate.RecentNameArray1);
- // if([reloadFlag isEqualToString:@"recent"])
- // {
- // [self recentContact];
- // }
- // else if([reloadFlag isEqualToString:@"vendor"])
- // {
- // [self vendorContact];
- // }
- // else if([reloadFlag isEqualToString:@"all"])
- // {
- // [self allContact];
- // }
- // else if([reloadFlag isEqualToString:@"client"])
- // {
- // [self clientContact];
- // }
- // else
- // {
- // [self reload];
- // }
- [super viewDidLoad];
- self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, (self.view.frame.size.width), self.view.frame.size.height-104);
- // Uncomment the following line to preserve selection between presentations.
- // self.clearsSelectionOnViewWillAppear = NO;
- // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
- // self.navigationItem.rightBarButtonItem = self.editButtonItem;
- self.navigationController.navigationBar.hidden=YES;
- [self.tableView reloadData];
- [ContactTableview reloadData];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- self.navigationController.navigationBarHidden = YES;
- [super viewWillAppear:animated];
- // CAGradientLayer *bgLayer3 = [BackgroundLayer blueGradient1];
- // bgLayer3.frame = self.view.bounds;
- // [self.view.layer insertSublayer:bgLayer3 atIndex:0];
- [FilterButton setImage:[UIImage imageNamed:@"nav_menu_icon"] forState:UIControlStateNormal];
- [FilterButton setContentEdgeInsets:UIEdgeInsetsMake(0, 4, 0, 0)];
- [self reload];
- NSString *ContactIdStr=[NSString stringWithFormat:@"%@",[[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:0]] objectAtIndex:0]];
- NSArray *afterSeprate = [[NSArray alloc]init];
- afterSeprate = [ContactIdStr componentsSeparatedByString:@"+"];
- NSString *detailText = [afterSeprate objectAtIndex:1];
- appdelegate.contactId=[NSString stringWithString:detailText];
- NSLog(@"viewWillAppear appdelegate.RecentNameArray1..... %@",appdelegate.RecentNameArray1);
- }
- - (void)viewDidUnload
- {
- conIdArray = nil;
- conNameArray = nil;
- conIdArray1 = nil;
- conNameArray1 = nil;
- conIdArray2 = nil;
- conNameArray2 = nil;
- RecentContactNameArray2 = nil;
- RecentContactIdArray2 = nil;
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- // Return the number of sections.
- if([serachBar.text isEqualToString:@""] || serachBar.text == nil)
- return [arrayOfCharacters count];
- else
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- // Return the number of rows in the section.
- if([serachBar.text isEqualToString:@""] || serachBar.text == nil)
- return [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:section]] count];
- else
- return [searchArray count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSLog(@"Reload");
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- }
- if([serachBar.text isEqualToString:@""] || serachBar.text == nil)
- {
- NSString *totalString = [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
- NSArray *afterSeprate = [[NSArray alloc]init];
- afterSeprate = [totalString componentsSeparatedByString:@"+"];
- NSString *cellText = [afterSeprate objectAtIndex:0];
- //NSString *detailText = [afterSeprate objectAtIndex:1];
- cell.textLabel.text = cellText;
- //cell.detailTextLabel.text=detailText;
- cell.textLabel.textColor=[UIColor blackColor];
- cell.imageView.image=[UIImage imageNamed:@"Profile.png"];
- NSLog(@"cellText.....%@",cellText);
- }
- else
- {
- NSArray *afterSeprate = [[NSArray alloc]init];
- afterSeprate = [[searchArray objectAtIndex:indexPath.row] componentsSeparatedByString:@"+"];
- NSString *cellText = [afterSeprate objectAtIndex:0];
- //NSString *detailText = [afterSeprate objectAtIndex:1];
- cell.textLabel.text = cellText;
- //cell.detailTextLabel.text=detailText;
- cell.textLabel.textColor=[UIColor blackColor];
- cell.imageView.image=[UIImage imageNamed:@"Profile.png"];
- NSLog(@"cellText...123.....%@",cellText);
- }
- return cell;
- }
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- if([serachBar.text isEqualToString:@""] || serachBar.text == nil)
- {
- if ([arrayOfCharacters count] == 0) {
- return @"";
- }
- return [NSString stringWithFormat:@"%@", [arrayOfCharacters objectAtIndex:section]];
- }
- else
- {
- return 0;
- }
- }
- - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
- if([serachBar.text isEqualToString:@""] || serachBar.text == nil)
- {
- NSMutableArray *toBeReturned = [[NSMutableArray alloc] init];
- [toBeReturned addObject:@"A"];
- [toBeReturned addObject:@"B"];
- [toBeReturned addObject:@"C"];
- [toBeReturned addObject:@"D"];
- [toBeReturned addObject:@"E"];
- [toBeReturned addObject:@"F"];
- [toBeReturned addObject:@"G"];
- [toBeReturned addObject:@"H"];
- [toBeReturned addObject:@"I"];
- [toBeReturned addObject:@"J"];
- [toBeReturned addObject:@"K"];
- [toBeReturned addObject:@"L"];
- [toBeReturned addObject:@"M"];
- [toBeReturned addObject:@"N"];
- [toBeReturned addObject:@"O"];
- [toBeReturned addObject:@"P"];
- [toBeReturned addObject:@"Q"];
- [toBeReturned addObject:@"R"];
- [toBeReturned addObject:@"S"];
- [toBeReturned addObject:@"T"];
- [toBeReturned addObject:@"U"];
- [toBeReturned addObject:@"V"];
- [toBeReturned addObject:@"W"];
- [toBeReturned addObject:@"X"];
- [toBeReturned addObject:@"Y"];
- [toBeReturned addObject:@"Z"];
- [toBeReturned addObject:@"#"];
- return toBeReturned;
- }
- else
- {
- return 0;
- }
- }
- - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
- if([serachBar.text isEqualToString:@""] || serachBar.text == nil)
- {
- NSInteger count = 0;
- for (NSString *character in arrayOfCharacters) {
- if ([character isEqualToString:title]) {
- return count;
- }
- count ++;
- }
- }
- else
- {
- return 0;
- }
- return 0;// in case of some eror donot crash d application
- }
- #pragma mark - Table view delegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // Navigation logic may go here. Create and push another view controller.
- if([serachBar.text isEqualToString:@""] || serachBar.text == nil)
- {
- NSString *ContactIdStr=[NSString stringWithFormat:@"%@",[[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]];
- NSArray *afterSeprate = [[NSArray alloc]init];
- afterSeprate = [ContactIdStr componentsSeparatedByString:@"+"];
- //NSString *cellText = [afterSeprate objectAtIndex:0];
- NSString *detailText = [afterSeprate objectAtIndex:1];
- appdelegate.contactId=[NSString stringWithString:detailText];
- }
- else
- {
- serachBar.text = nil;
- NSString *ContactIdStr=[NSString stringWithFormat:@"%@",[searchArray objectAtIndex:indexPath.row]];
- NSArray *afterSeprate = [[NSArray alloc]init];
- afterSeprate = [ContactIdStr componentsSeparatedByString:@"+"];
- //NSString *cellText = [afterSeprate objectAtIndex:0];
- NSString *detailText = [afterSeprate objectAtIndex:1];
- appdelegate.contactId=[NSString stringWithString:detailText];
- }
- // Pass the selected object to the new view controller.
- DetailView_iPad *event = [[DetailView_iPad alloc]initWithNibName:@"DetailView_iPad" bundle:nil];
- [detailViewController.navigationController pushViewController:event animated:YES];
- [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
- }
- - (void)setupIndexData {
- self.arrayOfCharacters = [[NSMutableArray alloc] init];
- self.objectsForCharacters = [[NSMutableDictionary alloc] init];
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
- NSMutableArray *arrayOfNames = [[NSMutableArray alloc] init];
- NSString *numbericSection = @"#";
- NSString *firstLetter;
- NSLog(@"ArrayFinal..%@",arrayFinal);
- for (NSString *item in arrayFinal)
- {
- firstLetter = [[item description] substringToIndex:1];
- // Check if it's NOT a number
- if ([formatter numberFromString:firstLetter] == nil)
- {
- /**
- * If the letter doesn't exist in the dictionary go ahead and add it the
- * dictionary.
- *
- * ::IMPORTANT::
- * You HAVE to removeAllObjects from the arrayOfNames or you will have an N + 1
- * problem. Let's say that start with the A's, well once you hit the
- * B's then in your table you will the A's and B's for the B's section. Once
- * you hit the C's you will all the A's, B's, and C's, etc.
- */
- firstLetter = [firstLetter uppercaseString];
- if (![objectsForCharacters objectForKey:firstLetter])
- {
- [arrayOfNames removeAllObjects];
- [arrayOfCharacters addObject:firstLetter];
- }
- [arrayOfNames addObject:[item description]];
- /**
- * Need to autorelease the copy to preven potential leak. Even though the
- * arrayOfNames is released below it still has a retain count of +1
- */
- [objectsForCharacters setObject:[arrayOfNames copy] forKey:firstLetter];
- }
- else
- {
- if (![objectsForCharacters objectForKey:numbericSection])
- {
- [arrayOfNames removeAllObjects];
- [arrayOfCharacters addObject:numbericSection];
- }
- [arrayOfNames addObject:[item description]];
- [objectsForCharacters setObject:[arrayOfNames copy] forKey:numbericSection];
- }
- }
- for(NSString *key in objectsForCharacters){
- NSArray *array = [objectsForCharacters valueForKey:key];
- [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
- [dataArray addObject:obj];
- }];
- }
- NSLog(@"arrayOfCharacters ::123 %@",arrayOfCharacters);
- // COULDN"T RELOAD TABLEVIEW HERE.. TRIED ALL THE FOLLOWING CODES TO RELOAD BUT NOTHING WORKED
- // [self.ContactTableview.dataSource tableView:ContactTableview cellForRowAtIndexPath:1];
- //[self.tableView reloadData];
- [ContactTableview reloadData];
- //// [self.tableViewController.tableView reloadData];
- //// [self.tableViewController.ContactTableview reloadData];
- ////
- //// [self.tableView cellForRowAtIndexPath:0];
- ////
- [self.ContactTableview cellForRowAtIndexPath:0];
- // [self.tableView clearsContextBeforeDrawing];
- //
- [self.tableView reloadData];
- // [self.ContactTableview reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
- // [self.ContactTableview reloadData];
- }
- # pragma mark - Other Methods
- -(void)reload
- {
- NSLog(@"Reload Method Called");
- reloadFlag=@"";
- arrayFinal = [[NSMutableArray alloc]init];
- for(int i=0; i<[appdelegate.names1 count]; i++)
- {
- NSString *string = [NSString stringWithFormat:@"%@+%@",[appdelegate.names1 objectAtIndex:i],[appdelegate.id2 objectAtIndex:i]];
- [arrayFinal addObject:string];
- }
- arrayFinal = (NSMutableArray *)[arrayFinal sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
- searchArray = [[NSMutableArray alloc]init];
- dataArray = [[NSMutableArray alloc]init];
- [self setupIndexData];
- }
- -(IBAction)clickAddContact:(id)sender
- {
- if ([appdelegate.PrivilegeAccess containsObject:@"21"])
- {
- AddContact *addcontact = [[AddContact alloc]init];
- [self.navigationController pushViewController:addcontact animated:YES];
- }
- else
- {
- [self dismissAllPopTipViews];
- NSString *contentMessage = nil;
- contentMessage = @"Not Authorized";
- popTipView = [[CMPopTipView alloc] initWithMessage:contentMessage];
- popTipView.delegate = self;
- [popTipView autoDismissAnimated:YES atTimeInterval:3.0];
- UIButton *button = (UIButton *)sender;
- [popTipView presentPointingAtView:button inView:self.view animated:YES];
- }
- }
- - (void)dismissAllPopTipViews
- {
- [popTipView dismissAnimated:YES];
- }
- - (void)popTipViewWasDismissedByUser:(CMPopTipView *)popTipView
- {
- //self.currentPopTipViewTarget = nil;
- }
- -(void) filterMethod
- {
- appdelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
- NSLog(@"Filter Method");
- NSLog(@"Filter appdelegate.RecentNameArray1 Contacts..%@",appdelegate.RecentNameArray1);
- CustomAlertView *customAlertView = [[CustomAlertView alloc]initWithTitle:@"Contacts"
- message:@"Select Option"
- delegate:self
- cancelButtonTitle:nil
- otherButtonTitles:@"Recent Contacts",@"Clients",@"Vendors",@"All", nil];
- [customAlertView show];
- }
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- switch (buttonIndex)
- {
- case 0: //red
- [self recentContact];
- break;
- case 1: //red
- [self clientContact];
- break;
- case 2:
- [self vendorContact];
- break;
- case 3: //blue
- [self allContact];
- break;
- default:
- break;
- }
- }
- -(void)recentContact
- {
- NSLog(@"Recent Contacts");
- arrayFinal = [[NSMutableArray alloc]init];
- for(int i=0; i<[appdelegate.RecentNameArray1 count]; i++)
- {
- NSString *string = [NSString stringWithFormat:@"%@+%@",[appdelegate.RecentNameArray1 objectAtIndex:i],[appdelegate.RecentIdArray1 objectAtIndex:i]];
- [arrayFinal addObject:string];
- }
- arrayFinal = (NSMutableArray *)[arrayFinal sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
- searchArray = [[NSMutableArray alloc]init];
- dataArray = [[NSMutableArray alloc]init];
- [self setupIndexData];
- }
- -(void)allContact
- {
- NSLog(@"All Contacts");
- arrayFinal = [[NSMutableArray alloc]init];
- for(int i=0; i<[appdelegate.names1 count]; i++)
- {
- NSString *string = [NSString stringWithFormat:@"%@+%@",[appdelegate.names1 objectAtIndex:i],[appdelegate.id2 objectAtIndex:i]];
- [arrayFinal addObject:string];
- }
- arrayFinal = (NSMutableArray *)[arrayFinal sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
- searchArray = [[NSMutableArray alloc]init];
- dataArray = [[NSMutableArray alloc]init];
- [self setupIndexData];
- }
- -(void)vendorContact
- {
- NSLog(@"Vendor Contacts");
- arrayFinal = [[NSMutableArray alloc]init];
- for(int i=0; i<[appdelegate.vendorNameArray1 count]; i++)
- {
- NSString *string = [NSString stringWithFormat:@"%@+%@",[appdelegate.vendorNameArray1 objectAtIndex:i],[appdelegate.vendorIdArray1 objectAtIndex:i]];
- [arrayFinal addObject:string];
- }
- arrayFinal = (NSMutableArray *)[arrayFinal sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
- searchArray = [[NSMutableArray alloc]init];
- dataArray = [[NSMutableArray alloc]init];
- [self setupIndexData];
- }
- -(void)clientContact
- {
- NSLog(@"Client Contacts");
- arrayFinal = [[NSMutableArray alloc]init];
- for(int i=0; i<[appdelegate.clientNameArray1 count]; i++)
- {
- NSString *string = [NSString stringWithFormat:@"%@+%@",[appdelegate.clientNameArray1 objectAtIndex:i],[appdelegate.clientIdArray1 objectAtIndex:i]];
- [arrayFinal addObject:string];
- }
- arrayFinal = (NSMutableArray *)[arrayFinal sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
- searchArray = [[NSMutableArray alloc]init];
- dataArray = [[NSMutableArray alloc]init];
- [self setupIndexData];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment