I have a tableview using ODRefreshControll. And i have a uislider which is in another view controller (let say myViewController) and this slider is changing a variable (let say myVariable) of tableview. The main issue is if i change myVariable from myViewController with slider and refresh the tableview, myVariable turns its initial value. I will provide my code but it is a little bit mess code, so please ask anything you do not understand from code. Here is my code:
At myTableView.h:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "ODRefreshControl.h"
@interface myTableView : UITableViewController
-(void)gettingVariableFromMyViewController;
@end
At myTableView.m
#import "MekanListesi.h"
#import "AppDelegate.h"
#import "Ayarlar.h"
@interface myTableView ()
@property(strong)NSNumber *myVariable;
@end
@implementation myTableView
@synthesize myVariable;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
-(void)gettingVariableFromMyViewController{
NSString *unsettedVariable = [(AppDelegate *)[[UIApplication sharedApplication] delegate] variableUniversal];
if (!unsettedVariable) {
unsettedVariable= @"10000000000000000";
}
NSNumberFormatter * NSNF= [[NSNumberFormatter alloc] init];
[NSNF setNumberStyle:NSNumberFormatterDecimalStyle];
self.myVariable=[DegmesinEllerimiz numberFromString:AlinanYariCap];
}
- (void)dropViewDidBeginRefreshing:(ODRefreshControl *)refreshControl
{
double delayInSeconds = 1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[refreshControl endRefreshing];
});
}
At myViewController.h
#import <UIKit/UIKit.h>
@interface myViewController : UIViewController
@property (weak, nonatomic) IBOutlet UISlider *mySlider;
- (IBAction)actionMySlider:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *myVariabelLabel;
@end
At myViewController.m
#import "myViewController.h"
#import "AppDelegate.h"
#import "myTableView.h"
@interface myViewController()
@end
@implementation myViewController
@synthesize myVariableLabel;
@synthesize mySlider;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)actionMySlider:(id)sender{
myVariableLabel.text = [NSString stringWithFormat:@"%1.1f",mySlider.value];
[(AppDelegate *)[[UIApplication sharedApplication] delegate] setuniversalVariable:[NSString stringWithFormat:@"%f",mySlider.value]];
myTableView *MTV=[[myTableView alloc]init];
[MTV gettingVariableFromMyViewController];
[MTV.tableView reloadData];
}
(At appdelegate universalVariable setted as
@property(nonatomic,retain)NSString *universalVariable;
@synthesize universalVariable;
)
note: I am coping and pasting that code from xcode and make some changes with names of methods, classes and variables due to the fact that my native language is not English, so there can be some mistakes about names of those, Please warn me if you see one of those errors.
Thank you.