i'm having a viewcontroller which has show segue to next view controller
but for each button which connected to show segue having webservice to call and response from webservice is storing in plist file and accessing in next view
my issue:when i click on button it is directly going to nextview without loading plist contents first time but when i'm go back and click on button it is showing plist contents
any help most appreciated
here is my plist creation code it is creating well but after the button click
if(connection == conn1)
{
NSError *e = nil;
classResponse = [NSJSONSerialization JSONObjectWithData:classData options:NSJSONReadingMutableLeaves error:&e];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"classesArray.plist"];
NSLog(@"file path is %@ ",path);
NSFileManager *fileManager=[NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:path])
{
NSString *bundle = [[[NSBundle mainBundle]resourcePath]stringByAppendingString:@"classesArray.plist"];
//NSString *bundle = [[NSBundle mainBundle]pathForResource:@"create" ofType:@"plist"];
[fileManager copyItemAtPath:bundle toPath:path error:&error];
}
[classResponse writeToFile:path atomically:YES];
}
i'm using tableview with custom cell in next view to load from plist here is my code
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [className count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cellId";
classesTeacher *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
if (cell == nil) {
cell = [[classesTeacher alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
long row = [indexPath row];
cell.classname.text = className[row];
cell.classdescription.text = classDescription[row];
cell.classCode.text = classRef[row];
cell.studentcount.text=classIds[row];
return cell;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"classesArray.plist"];
NSDictionary *StudentDict=[[NSDictionary alloc]initWithContentsOfFile:path];
// NSLog(@" QuizDict has %@ ",StudentDict);
//get all values for a key in array
NSArray *See = StudentDict[@"alldata"];
className= [See valueForKey:@"class_name"];
classDescription=[See valueForKey:@"class_description"];
classRef=[See valueForKey:@"class_ref"];
classIds=[See valueForKey:@"number_of_students"];
//classId = [See objectAtIndex:@"classid"];
NSLog(@"class id %@",classId);
NSLog(@"class id is %@",classIds);
UIImage *backImage = [UIImage imageNamed:@"s-left-arrow.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(0, 0, backImage.size.width, backImage.size.height);
[backButton setImage:backImage forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(pushBackButton:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton] ;
self.navigationItem.hidesBackButton = YES;
self.navigationItem.leftBarButtonItem = backBarButtonItem;
[self.table reloadData];
// Do any additional setup after loading the view.
}