New Method For API Call

[[[NSURLSession sharedSession] dataTaskWithRequest:theRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {

NSLog(@”error===> %@”,error);

} else {

NSMutableDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
recordArr = [[NSMutableArray alloc] initWithArray:[jsonObject valueForKey:@”record”]];
NSLog(@”recordArr===> %@”,recordArr);

 

}
}] resume];

Add Via For Loop with Dictionary

for (int i = 0; i<self.dataArray.count; i++)
{
NSDictionary *innerDic = self.dataArray[i];

NSString *strQuery = [NSString stringWithFormat:@”INSERT INTO main.tblFav (\”memId\”,\”firstname\”,\”fathername\”,\”lastname\”,\”address1\”,\”address2\”,\”area\”,\”city\”,\”native\”,\”phMobile\”,\”phHome\”,\”phOffice\”,\”gender\”,\”dob\”,\”height\”,\”education\”,\”occupation\”,\”srNo\”,\”Cat\”,\”Subcat\”) VALUES (\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”,\”%@\”)”,[innerDic objectForKey:@”Id”],[innerDic objectForKey:@”FirstName”],[innerDic objectForKey:@”MiddleName”],[innerDic objectForKey:@”LastName”],@””,@””,@””,[innerDic objectForKey:@”City”],[innerDic objectForKey:@”Native”],[innerDic objectForKey:@”PhnMobile”],[innerDic objectForKey:@”PhnHome”],[innerDic objectForKey:@”PhnWork”],@””,@””,@””,@””,@””,@””,@”1″,subCat];

[database executeUpdate:strQuery];

}

===================****************====================

NSString *insertSQL = [NSString stringWithFormat:
@”INSERT INTO tblCartList (ProductID,ProductTitle,ProductDate,ProductTime,ProductImage,TotalCoast,Quantity,CartBadgeCount,ProductDetails,ProductPrice) VALUES (\”%@\”, \”%@\”, \”%@\”, \”%@\”, \”%@\”, \”%f\”, \”%@\”, \”%d\”, \”%@\”, \”%@\”)”,strProductID,
lblProductTitle.text,txtDeliveryDt.text,txtDeliveryTime.text, strImagURL , total,
lblQuantity.text,cartbadge,strProductDetails,strProductPrice];

BOOL success=[database executeUpdate:insertSQL];

 

====================******************====================

for (NSDictionary *dictn in taskDetailsArray)
{
if ([[dictn objectForKey:@”TaskTypeName”]isEqualToString:@”Procedure”]){

[ActivityArry addObject:dictn];
}
}

====================******************======================

//Short array and display list as a date Wise…..
for (int i = 0; i<reverseOrder.count; i++) {
//Set date as per Order…..
tmpString = [[reverseOrder objectAtIndex:i] objectForKey:@”ActivityDate”];
if (![arrKeys containsObject:tmpString])
{
[arrKeys addObject:tmpString];
}
}
for (int i=0 ;i<[arrKeys count]; i++)
{
NSMutableArray *arr=[[NSMutableArray alloc]init];
for (int j=0; j<[reverseOrder count]; j++)
{
NSMutableDictionary *dict=[[NSMutableDictionary alloc]initWithDictionary:[arrayData objectAtIndex:j]];
NSString *strDate = [dict objectForKey:@”ActivityDate”];

if ([[arrKeys objectAtIndex:i] isEqual:strDate])
{
[arr addObject:dict];
}
}
[historyDataArray addObject:arr];
}

 

============================================================

– (void)addDataDB{
database=[FMDatabase databaseWithPath:self.path];

if(![database open])
NSLog(@”%@”,[database lastErrorMessage]);

NSString *strQuery;

for (int i = 0; i < recordArr.count; i++) {

[database open];
NSDictionary *dict = [recordArr objectAtIndex:i];

if ([dict objectForKey:@”name”] == nil && [dict objectForKey:@”sub_cat_id”])
{
NSLog(@”Name not found”);
return;
}
else if ([dict objectForKey:@”sub_cat_id”] == nil)
{
NSLog(@”sub_cat_id not found”);
return;
}

NSString *name = [dict valueForKey:@”name”];
NSString *sub_cat_id = [NSString stringWithFormat:@”%@”,[dict valueForKey:@”sub_cat_id”]];

strQuery = [NSString stringWithFormat:@”INSERT INTO tblEmp (\”Name\”,\”Age\”) VALUES (\”%@\”,\”%@\”)”,name,sub_cat_id];

BOOL success=[database executeUpdate:strQuery];

if(success){
self.msg=@”record insertd successfully”;
NSLog(@”record insertd successfully”);
}
else{
self.msg=[database lastErrorMessage];
}

[database close];
}
}

=========

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

NSString * identifier=[NSString stringWithFormat:@”MenuCell”];
MenuCell *cell=(MenuCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if(cell == nil){
cell=[[MenuCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier ];
}
NSLog(@”recordArr===> %@”,recordArr);

NSDictionary *dict = [recordArr objectAtIndex:indexPath.row];

cell.lblTitle.text = [dict valueForKey:@”name”];
return cell;

}

WebService and Database…..

FMDB Class=>https://github.com/appcoda/FMDBDemo

AppDelegate.h

-(NSString *)encodesmiliesandstring:(NSString *)convertstring;
-(NSString *)encodeUrl:(NSString *)string;

AppDelegate.m

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

NSString *documentpath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(@”documentpath : %@”,documentpath);

NSString *foofile=[documentpath stringByAppendingPathComponent:@”simple.sqlite”];

NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:foofile forKey:@”databasePath”];
[defaults synchronize];

BOOL fileexist=[[NSFileManager defaultManager]fileExistsAtPath:foofile];

if(!fileexist)
{
NSString *sourcepath=[[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:@”simple.sqlite”];
NSError *error=nil;

if([[NSFileManager defaultManager]copyItemAtPath:sourcepath toPath:foofile error:&error])
{
NSLog(@”default file copy….”);
}
else
{
NSLog(@”Error descriptin—–>%@\n”,[error localizedDescription]);
NSLog(@”Error reason—->%@”,[error localizedFailureReason]);
}
}

}

-(NSString *)encodeUrl:(NSString *)string
{
NSString *convertedstring=[NSString stringWithString:string];
convertedstring=[convertedstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return convertedstring;
}

-(NSString *)encodesmiliesandstring:(NSString *)convertstring
{
NSString *convertedstring=[NSString stringWithString:convertstring];
convertedstring=[convertedstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return convertedstring;
}

ViewController.h

#import “AppDelegate.h”
#import “FMDatabase.h”

@interface MenuCell : UITableViewCell

@property (strong , nonatomic)IBOutlet UILabel *lblTitle;
@property (nonatomic , weak) IBOutlet UIImageView *imgLogo;

@end

@interface ViewController : UIViewController{

IBOutlet UITableView *tblData;
NSMutableArray *recordArr;
AppDelegate *app;
FMDatabase *database;
NSUserDefaults *defaults;

}
@property(strong,nonatomic)NSString *path;
@property(strong,nonatomic)NSString *msg;

ViewController.m

@implementation MenuCell

@synthesize lblTitle,imgLogo;
@end

– (void)viewDidLoad {
[super viewDidLoad];
defaults=[NSUserDefaults standardUserDefaults];
self.path=[defaults stringForKey:@”databasePath”];
app = (AppDelegate *)[[UIApplication sharedApplication]delegate];

//NSString * url=[NSString stringWithFormat:@”%@api/user/login?email=%@&password=%@”,BaseUrl,txtEmail.text,txtPwd.text]; //LIVE

NSString *strURL = @”http://ec2-35-164-90-67.us-west-2.compute.amazonaws.com/&#8221;;
strURL = [NSString stringWithFormat:@”%@api/getSubCategories?category_id=%@”,strURL,@”1″];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[app encodesmiliesandstring:strURL]] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:9000];
[theRequest setHTTPMethod:@”POST”];
[theRequest addValue:@”application/json” forHTTPHeaderField:@”Content-Type”];
NSLog(@”webservice called for post is %@”,theRequest);

[NSURLConnection sendAsynchronousRequest:theRequest queue:[NSOperationQueue mainQueue]completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{

if ([(NSHTTPURLResponse *)response statusCode]==200)
{
NSMutableDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

NSNumber *resultStr = [jsonObject objectForKey:@”status”];

if ([resultStr intValue] == 1){
NSLog(@”SUCCESS”);

recordArr = [[[NSMutableArray alloc] initWithArray:[jsonObject valueForKey:@”record”]] valueForKey:@”name”];
[self addDataDB];
[tblData reloadData];

}
else{
}
}
else
{
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@”Alert!” message:@”Could not connect to the network. Please try again in a few seconds.” preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *no = [UIAlertAction actionWithTitle:@”Ok” style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:no];
[self.navigationController presentViewController:alert animated:YES completion:nil];
}
}];
}

 

– (void)addDataDB{
database=[FMDatabase databaseWithPath:self.path];
if(![database open])
NSLog(@”%@”,[database lastErrorMessage]);

NSString *strQuery;

for (int i = 0; i<recordArr.count; i++) {

NSMutableDictionary *dict=[[recordArr objectAtIndex:i] mutableCopy];
NSLog(@”dbArryData===> %@”,dict);
strQuery = [NSString stringWithFormat:@”INSERT INTO tblEmp (\”Name\”) VALUES (\”%@\”)”,[[recordArr objectAtIndex:i] mutableCopy]];
BOOL success=[database executeUpdate:strQuery];

if(success){
self.msg=@”record insertd successfully”;
NSLog(@”record insertd successfully”);
}
else{
self.msg=[database lastErrorMessage];
}
}

[database close];
}

– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

// Return the number of sections.
return 1;
}

– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

// Return the number of rows in the section.
return recordArr.count;

}

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

NSString * identifier=[NSString stringWithFormat:@”MenuCell”];
MenuCell *cell=(MenuCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if(cell == nil){
cell=[[MenuCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier ];
}
NSLog(@”recordArr===> %@”,recordArr);
cell.lblTitle.text = [recordArr objectAtIndex:indexPath.row];
return cell;

}

– (IBAction)saveInDataBase:(id)sender{
SecondViewController *objSecondVC = [self.storyboard instantiateViewControllerWithIdentifier:@”SecondViewController”];
[self.navigationController pushViewController:objSecondVC animated:YES];
}

SecondViewController.h

#import “FMDatabase.h”

@interface MenuDisplayCell : UITableViewCell

@property (strong , nonatomic)IBOutlet UILabel *lblTitle;
@property (nonatomic , weak) IBOutlet UIImageView *imgLogo;

@end

@interface SecondViewController : UIViewController{

NSMutableArray *dbArryData;
FMDatabase *database;
NSUserDefaults *defaults;
IBOutlet UITableView *tblDisplyDB;

}
@property(strong,nonatomic)NSString *path;
@property(strong,nonatomic)NSString *msg;
@end

SecondViewController.m

@implementation MenuDisplayCell

@synthesize lblTitle,imgLogo;
@end

– (void)viewDidLoad {
[super viewDidLoad];

defaults=[NSUserDefaults standardUserDefaults];
self.path=[defaults stringForKey:@”databasePath”];

database=[FMDatabase databaseWithPath:self.path];
if(![database open])
NSLog(@”%@”,[database lastErrorMessage]);

NSString *query=[NSString stringWithFormat:@”select * from tblEmp”];
FMResultSet *result=[database executeQuery:query];

dbArryData=[[NSMutableArray alloc]init];

while([result next])
{

NSDictionary *groupDict=@{
@”Name”:[result stringForColumn:@”Name”]!=nil?[result stringForColumn:@”Name”]:@””,

};

[dbArryData addObject:groupDict];
}
NSLog(@”arrDBCartDetails===> %@”,dbArryData);

}

– (IBAction)backBtnClick:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}

– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}

– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return dbArryData.count;
}

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

NSString * identifier=[NSString stringWithFormat:@”MenuDisplayCell”];
MenuDisplayCell *cell=(MenuDisplayCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if(cell == nil){
cell=[[MenuDisplayCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier ];
}
cell.lblTitle.text = [[dbArryData valueForKey:@”Name”] objectAtIndex:indexPath.row];
return cell;
}

MT Demo

ViewController.h

#import <UIKit/UIKit.h>

#import <AVFoundation/AVFoundation.h>

#import <MediaPlayer/MediaPlayer.h>

@interface ViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>

@property MPMoviePlayerViewController *moviePlayer;

@end

ViewController.m

#import “ViewController.h”

@interface ViewController ()

@property NSArray * jsonData ;

@property NSMutableArray *name;

@property NSMutableArray *photo;

@property NSMutableArray *url;

@end

@implementation ViewController

– (void)viewDidLoad {

    [super viewDidLoad];

    

    self.name = [[NSMutableArray alloc] init];

    self.photo = [[NSMutableArray alloc] init];

    self.url = [[NSMutableArray alloc] init];

    

    NSURL *url = [NSURL URLWithString:@”http://project-demo-server.info/iphonevideo/displayvieo.php?cat=office&#8221;];

    

    NSData *data = [NSData dataWithContentsOfURL:url];

    

    NSData *photo ;

    

    self.jsonData = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];

    

    for(int i = 0; i<self.jsonData.count; i++)

    {

        

        [self.name addObject:[[self.jsonData objectAtIndex:i] valueForKey:@”videoname”]];

        

        

        photo = [[NSData alloc] initWithContentsOfURL:[[NSURL alloc] initWithString:@”http://www.project-demo-server.info/iphonevideo/images/Neck-and-Wrist-Stretches.jpg&#8221;]];

        

        [self.photo addObject:[UIImage imageWithData:photo]];

        

        [self.url addObject:[[NSURL alloc ] initWithString:[[self.jsonData objectAtIndex:i] valueForKey:@”video”]]] ;

    

    }

    // Do any additional setup after loading the view, typically from a nib.

}

– (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

#warning Potentially incomplete method implementation.

    // Return the number of sections.

    return 1;

}

– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

#warning Incomplete method implementation.

    // Return the number of rows in the section.

    return [self.name count];

}

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@”cell” forIndexPath:indexPath];

     if(cell == nil)

     {

     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@”cell”];

     }

     

     cell.textLabel.text = [self.name objectAtIndex:indexPath.row];

     

     cell.imageView.image = [self.photo objectAtIndex:indexPath.row];

     

return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    

   // NSString *path = [[NSBundle mainBundle]pathForResource:

                     // @”videoTest” ofType:@”mov”];

    

    self.moviePlayer = [[MPMoviePlayerViewController

                    alloc]initWithContentURL:[self.url objectAtIndex:indexPath.row]];

    [self presentModalViewController:self.moviePlayer animated:NO];

}

@end

Simple API Load in TableView

//Add AFNetworking FrameWork………………With UtilityLibrary and AFNetworking…. With .xib CELL or Implement Tablecell In Class

NewsEventsCellTableViewCell.h

#import <UIKit/UIKit.h>

@interface NewsEventsCellTableViewCell : UITableViewCell{

        IBOutlet UIImageView *imgLblBg;

      IBOutlet UILabel *lblDate;

}

@property (nonatomic , retain) IBOutlet UIImageView *imgLblBg;

@property (nonatomic , retain) IBOutlet UILabel *lblDate;

@end

=============================

NewsEventsCellTableViewCell.m

#import “NewsEventsCellTableViewCell.h”

@implementation NewsEventsCellTableViewCell

@synthesize imgLblBg,lblDate;

– (void)awakeFromNib {

    // Initialization code

}

– (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state

}

@end

#import <UIKit/UIKit.h>

@interface NewsEventsCellTableViewCell : UITableViewCell{

    

    IBOutlet UIImageView *imgLblBg;

    

    IBOutlet UILabel *lblDate;

}

@property (nonatomic , retain) IBOutlet UIImageView *imgLblBg;

@property (nonatomic , retain) IBOutlet UILabel *lblDate;

@end

NewsEventsVC.h

#import <UIKit/UIKit.h>

@interface BranchListCell : UITableViewCell

@property (strong, nonatomic) IBOutlet UILabel *lblBranchName;

@property (strong , nonatomic) IBOutlet UIImageView *imgArrow;

@end

@interface NewsEventsVC : UIViewController{

    

    IBOutlet UILabel *lblHeader;

    

    IBOutlet UIImageView *imgTopView;

    }

@property (weak, nonatomic) IBOutlet UITableView *tableVIew;

@property (nonatomic, strong) NSMutableArray *tableViewDataSources;

@end

===============================================

NewsEventsVC.m

#import “NewsEventsVC.h”

#import “UtilityLibrary.h”

#import “NewsEventsCellTableViewCell.h”

@implementation BranchListCell

@end

@interface NewsEventsVC ()

@end

@implementation NewsEventsVC

– (void)viewDidLoad {

    [super viewDidLoad];

    self.tableViewDataSources = [[NSMutableArray alloc] init];

    [self getNewsEventsList];

}

#pragma mark – UITableView DataSource and Delegate Methods –

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.tableViewDataSources.count;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    /*NewsEventsCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@”NewsEventsCellTableViewCell”];

    if (cell == nil) {

        

        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@”NewsEventsCellTableViewCell” owner:self options:nil];

        cell = [array objectAtIndex:0];

    }

    NSLog(@”tableViewDataSources==>%@”,self.tableViewDataSources);

    cell.lblDate.text = [NSString stringWithFormat:@”%@”,[[self.tableViewDataSources objectAtIndex:indexPath.row] objectForKey:@”HospitalBranchName”]];

    */

    

    NSString * identifier=[NSString stringWithFormat:@”BranchListCell”];

    BranchListCell *cell=(BranchListCell *)[tableView dequeueReusableCellWithIdentifier:identifier];

    if(cell == nil){

        cell=[[BranchListCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier ];

    }

    cell.lblBranchName.text = [NSString stringWithFormat:@”%@”,[[self.tableViewDataSources objectAtIndex:indexPath.row] objectForKey:@”HospitalBranchName”]];

     return cell;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return 92;

}

#pragma mark – Remove Space In URl

-(NSString *)encodesmiliesandstring:(NSString *)convertstring

{

    NSString *convertedstring=[NSString stringWithString:convertstring];

    convertedstring=[convertedstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    return convertedstring;

}

-(void)getNewsEventsList

{

    

//http://www.dev3.mybynde.com/desktopmodules/HaloWebAPI/API/Hospital/GetHospitalBranchByHospitalID?HospitalID=HOS4341&UserID=2110&UserRole=Hospital_Admin

    NSString *strURL = @”http://www.dev3.mybynde.com/desktopmodules/HaloWebAPI/API/&#8221;; //LIVE

    

        NSString * url=[NSString stringWithFormat:@”%@Hospital/GetHospitalBranchByHospitalID?HospitalID=%@&UserID=%@&UserRole=%@”,strURL,@”HOS4341″,@”2110″,@”Hospital_Admin”]; //old

        

        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[self encodesmiliesandstring:url]] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:9000];

        [theRequest setHTTPMethod:@”GET”];

        [theRequest addValue:@”application/json” forHTTPHeaderField:@”Content-Type”];

        NSLog(@”webservice called for post is %@”,theRequest);

        

    

        [NSURLConnection sendAsynchronousRequest:theRequest queue:[NSOperationQueue mainQueue]completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)

         

         {

             

             if ([(NSHTTPURLResponse *)response statusCode]==200)

             {

                 

                 NSMutableDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

                 NSString * resultStr = [jsonObject objectForKey:@”Result”];

                 if([resultStr isEqualToString:@”True”]){

                     

                     //Add All Json Responce In branchListArr….. for display in TableView List…..

                     _tableViewDataSources=[jsonObject valueForKey:@”HospitalBranchList”];

                     

//                     NSMutableArray *arryHospital = [[NSMutableArray alloc] init];

//                     [arryHospital addObject:jsonObject];

//                     strImg = [[[arryHospital objectAtIndex:0] valueForKey:@”Hospital”] valueForKey:@”HospitalLogo”];

//                     

//                    

//                     [_imgLogo sd_setImageWithURL:[NSURL URLWithString:strImg]

//                                 placeholderImage:nil

//                                        completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

//                                            

//                                            // [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

//                                            if (image){

//                                                [_imgLogo setImage:image];

//                                                [_objActivity stopAnimating];

//                                                _objActivity.hidden = YES;

//                                            }else{

//                                                [_objActivity stopAnimating];

//                                            }

//                                        }];

                     [_tableVIew reloadData];

                 }

                 else{

                     NSLog(@”False”);

                 }

             }

             else

             {

                 UIAlertView * alert =[[UIAlertView alloc]initWithTitle:@”Alert!”

                                                                message:@”Could not connect to the network. Please try again in a few seconds.”

                                                               delegate:nil

                                                      cancelButtonTitle:@”Ok”

                                                      otherButtonTitles:nil, nil];

                 [alert show];

                 

             }

         }];

        

   

    

    

}

@end

WS and ADD in DB

1)//IN APPDELEGATE……………………….

 

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

       [self checkDatabase];

    return YES;

   }

– (void)checkDatabase

{

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDir = [documentPaths objectAtIndex:0];

    NSString *databasePath = [documentsDir stringByAppendingPathComponent:@”TestData.sqlite”];

    NSString *databaseName = @”TestData.sqlite”;

    NSFileManager *fileManager = [NSFileManager defaultManager];

        NSLog(@”%@ === %@”,databaseName,databasePath);

        if(![fileManager fileExistsAtPath:databasePath])

    {

        NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath]

                                         stringByAppendingPathComponent:databaseName];

        [fileManager removeItemAtPath:databasePath error:nil];

        [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];

    }

    else

    {

        NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];

        [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];

    }

}

2) Add Class TestData add as NSObject……..

TestData.h

#import <Foundation/Foundation.h>

#import “sqlite3.h”

@interface TestData : NSObject

@property (nonatomic, readwrite) NSInteger  VideoID;

@property (nonatomic, strong) NSString   *videoName;

@property (nonatomic, strong) NSString   *imgPhoto;

@property (nonatomic, strong) NSString   *imgVideoURl;

+ (NSInteger)addRecord:(TestData *)sObj;

+ (NSMutableArray *)readRecords;

@end

TestData.m

#import “TestData.h”

@implementation TestData

+ (NSInteger)addRecord:(TestData *)sObj

{

    NSInteger retVal = false;

    

    NSString *query = [NSString stringWithFormat:

                       @”INSERT INTO TestData (videoName, imagePhoto, imageVideoUrl) VALUES (‘%@’, ‘%@’, ‘%@’)”,

                       sObj.videoName,

                       sObj.imgPhoto,

                       sObj.imgVideoURl

                       ];

    

    sqlite3 *db;

    

    

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDir = [documentPaths objectAtIndex:0];

    NSString *dbPath = [documentsDir stringByAppendingPathComponent:@”TestData.sqlite”];

    

    

    

    if(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK)

    {

        sqlite3_stmt *compiledStatement;

        

        if(sqlite3_prepare_v2(db,[query UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)

        {

            sqlite3_step(compiledStatement);

        }

        

        sqlite3_finalize(compiledStatement);

        

        retVal = sqlite3_last_insert_rowid(db);

        

        

        

    }

    sqlite3_close(db);

    

    return retVal;

}

+ (NSMutableArray *)readRecords

{

    NSMutableArray *recordsArr = [[NSMutableArray alloc] init];

    

    NSString *query = [NSString stringWithFormat:@”SELECT * FROM TestData ORDER BY videoName”];

    

    sqlite3 *db;

    

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDir = [documentPaths objectAtIndex:0];

    NSString *dbPath = [documentsDir stringByAppendingPathComponent:@”TestData.sqlite”];

    

    if(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK)

    {

        sqlite3_stmt *compiledStatement;

        

        

        if(sqlite3_prepare_v2(db,[query UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)

        {

            while(sqlite3_step(compiledStatement) == SQLITE_ROW)

            {

               

      TestData *sObj = [[TestData alloc] init];

                

                sObj.VideoID = sqlite3_column_int(compiledStatement, 0);

                

                sObj.videoName = [NSString stringWithUTF8String😦char *)sqlite3_column_text(compiledStatement, 1)];

                sObj.imgPhoto = [NSString stringWithUTF8String😦char *)sqlite3_column_text(compiledStatement, 2)];

                sObj.imgVideoURl = [NSString stringWithUTF8String😦char *)sqlite3_column_text(compiledStatement, 3)];

                [recordsArr addObject:sObj];

                

                NSLog(@”%@”,sObj);

            }

        }

        sqlite3_finalize(compiledStatement);

    }

    sqlite3_close(db);

    

    return recordsArr;

}

@end

3)MyVideoCell.h with .XIB

#import <UIKit/UIKit.h>

#import “TestData.h”

@interface MyVideoCell : UIViewController

@property (nonatomic, strong) IBOutlet UILabel  *lblVideoName;

@property (nonatomic, strong) IBOutlet UIImageView  *imgVideo;

@property (nonatomic, strong) TestData *testObj;

@end

MyVideoCell.m

#import “MyVideoCell.h”

@interface MyVideoCell ()

@end

@implementation MyVideoCell

– (void)viewDidLoad {

    [super viewDidLoad];

    

    [self.lblVideoName setText:self.testObj.videoName];

    

    NSString *ImageURL = self.testObj.imgPhoto;

    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];

    self.imgVideo.image = [UIImage imageWithData:imageData];

    // Do any additional setup after loading the view from its nib.

}

– (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

/*

#pragma mark – Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

– (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/

@end

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

{

    IBOutlet UITableView *tblData;

    NSMutableArray *recordArr;

}

@end

ViewController.m

#import “ViewController.h”

#import “MyVideoCell.h”

#import “TestData.h”

#import “VideoVC.h”

@interface ViewController ()

@end

@implementation ViewController

– (void)viewDidLoad {

    [super viewDidLoad];

}

– (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    

    recordArr = [TestData readRecords];

    

    [tblData reloadData];

}

– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return 60;

}

– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return recordArr.count;

}

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@”Cell”];

    

    cell.selectionStyle = UITableViewCellSelectionStyleGray;

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    

    TestData *currentSobj = recordArr[indexPath.row];

    

    MyVideoCell *mcv = [[MyVideoCell alloc] init];

    

    mcv.testObj = currentSobj;

    

    

    [cell.contentView addSubview:mcv.view];

    

    return cell;

}

– (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    VideoVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:@”VideoVC”];

    

    vc.testObj = recordArr[indexPath.row];

    

    [self.navigationController pushViewController:vc animated:YES];

}

– (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end