简体   繁体   中英

iOS method in data controller isn't being called

I am trying to call a method in my data controller object to load the data for my application, but for some reason it is not being called. Below is what I have done to initialize it. Any help would be greatly appreciated.

ViewController:

header file:

#import <UIKit/UIKit.h>

@class DetailViewController;
@class DataController;

#import <CoreData/CoreData.h>
#import "JointCAD.h"

@interface TableViewController : UITableViewController {

}

@property (nonatomic, assign) DataController *dataController;

@end

implementation file:

#import "TableViewController.h"
#import "DataController.h"

@implementation TableViewController

@synthesize dataController;

- (void)viewDidLoad {

[dataController refreshData];

}

@end

Data Controller:

header file:

#import <Foundation/Foundation.h>
#import "JointCAD.h"
#import "JointCADXMLParser.h"
#import "TFHpple.h"

@interface DataController : NSObject {

    TFHpple *xpathParser;
}

- (void)refreshData;

- (void)initXMLParser;

- (void)noCallsMessage;

- (void)noInternetMessage;

@end

implementation file:

#import "DataController.h"

@implementation DataController

XMLParser *xmlParser;

- (void)refreshData {

NSLog("Some Method");

}

Is 'dataController' Object being set by some other class? - I believe that's why you have set it as a property? Right?

If No, then Remove the property,@synthesize of 'dataController' and try simple allocation of your 'dataController' object and then try calling your method.

Hope it helps.

You either need to initialize "DataController" prior to actually calling one of it's methods, or you need to make the method, "refreshData" a class by changing it's "-" to a "+".

If you need an instance callback instead. You need to rewrite "viewDidLoad" like this:

- (void)viewDidLoad {

DataController *dataController = [[DataController alloc] init];
[dataController refreshData];

}

And get rid of the property declaration of dataController because you haven't initialized it. If you would prefer a property declaration instead, simply allocate the viewcontroller prior to calling a function from it.

- (void)viewDidLoad {
dataController = [[DataController alloc] init];
[dataController refreshData];

}

One last thing to note is that I (and probably Ray) assume that you're using a storyboard configuration. If you are using a xib configuration, you need to add initWithNibName: to each initialization of the view controller.

I hope that's helpful!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM