1,105,423 Community Members

How to reference objects defined in another class?

Member Avatar
SpokaneDude
Newbie Poster
4 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I had my iPhone app working, developed with Storyboard. I decided to take all of the methods that belonged in a SQLite method and move them to a new SQLite class (.h and .m).

Now I have errors that I can't seem to get rid of. The basic problem is the textfields on the "scene" are now unreachable from the SQLite class (they are in another class, where they belong). The properties are defined in EDVController.m... I am trying to reach them from SQLite.m.

I have read the docs, but can't find anything that fits my problem.

How do I do this?

Member Avatar
peter_budo
Code tags enforcer
7,939 posts since Dec 2004
Reputation Points: 2,502 [?]
Q&As Helped to Solve: 1,028 [?]
Skill Endorsements: 66 [?]
Moderator
Featured
 
1
 

Simple, when you call method to interact with database provide parameters with it instead of trying to get direct access.
Example, this is very simplified JAVA!!!
Before change

public boolean login(){
PreparedStatement preparedStatement = null;
	try{
		String strQuery = 
		"SELECT * FROM user WHERE uid=? AND password=? AND";
				
		preparedStatement = conn.prepareStatement(strQuery);
		preparedStatement.setString(1,usernameTextField.getText());
		preparedStatement.setString(2,passwordTextField.getText());

would become

public boolean login(String username, String password){
PreparedStatement preparedStatement = null;
	try{
		String strQuery = 
		"SELECT * FROM user WHERE uid=? AND password=? AND";
				
		preparedStatement = conn.prepareStatement(strQuery);
		preparedStatement.setString(1,username);
		preparedStatement.setString(2,password);

and you will call it from your user interface presumable on button click as

public void actionPerformed(){
    DataManager manager = new DataManager(); //Your database class
    manager.login(usernameTextField.getText(), passwordTextField.getText());
Question Answered as of 2 Years Ago by peter_budo
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: