我有一个使用 ODRefreshControll 的表格视图。我有一个 uislider,它位于另一个视图控制器(比如说 myViewController)中,这个滑块正在更改 tableview 的变量(比如说 myVariable)。主要问题是,如果我使用滑块从 myViewController 更改 myVariable 并刷新 tableview,myVariable 将变为其初始值。我将提供我的代码,但它是一个有点乱的代码,所以请询问您从代码中不理解的任何内容。这是我的代码:
At myTableView.h:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "ODRefreshControl.h"
@interface myTableView : UITableViewController
-(void)gettingVariableFromMyViewController;
@end
在 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];
});
}
在 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
在 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];
}
(在 appdelegate 通用变量设置为
@property(nonatomic,retain)NSString *universalVariable;
@synthesize universalVariable;
)
注意:由于我的母语不是英语,我正在从 xcode 处理和粘贴该代码并对方法、类和变量的名称进行一些更改,因此这些名称可能存在一些错误,如果您会看到其中一个错误。
谢谢你。