Help Loading Different Views from other class view controllers

Joined
Apr 27, 2011
Messages
10
Reaction score
0
Points
1
*edit here is the complete project in a zip file. no Viruses from my end seeing how im uploading fro school. PLease feel free to look at the code but don't Steal it. Whouldnt be worth taking anyways (grumble amature coding)
http://www.mediafire.com/?ja4bfbcypspiaar

Im sorry for any ambiguity through the title. Hello, my name is brad. im taking an xocde development class as an elective in college. for my final project i am creating a simple rpg style type game. this is where im running into errors. I have the first start screen which incompasses a FinalViewController.h .m and .xib file(a class view controller). when the first screen loads it prompts a view with two options(buttons). the first button loads a second class view controller(SaveViewController.h .m and .xib). This works fine. my Problem Occurs when i click another button in a diffrent view from the SaveViewController, which calls a method from FinalViewController.


heres some code Snipplets i think might be helpful?

From FinalViewController.m

//this is the method used to remove the save class view and load the //Homeworld class view. i know the method works because when i call it // from inside the FinalViewController it works sucessfully. However when i // try and call it from inside SaveViewController.

Code:
-(void)LoadHomeWorld{
    [saveViewController.view removeFromSuperview];
    [self.view insertSubview:homeWorldController.view atIndex:1];
}
Code:
heres the complete SaveView Controller .h and .m files

//
//  SaveViewController.h
//  Final
//
//  Created by wctc on 4/25/11.
//  Copyright 2011 WCTC. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "CharData.h"
#import "FinalViewController.h"
@interface SaveViewController : UIViewController {
    CharData *charData;
    int SaveCount;
    IBOutlet UIButton *loadButton;
    IBOutlet UIPickerView *thePickerView;
    IBOutlet FinalViewController* finalViewController;
    NSMutableArray *charSaveArray;
    int charSaveMarker;
    IBOutlet UITextField *txtNewChar;

   
    IBOutlet UIView *viewSplash;
    IBOutlet UIView *viewNewChar;

}
-(NSString*)PassNewCharName;
- (IBAction)tapNewChar:(id)sender;


- (IBAction)tapCreateNewChar:(id)sender;

@end

I REMOVED SOME EXCESS NON RELATED CODE THE THE FILE BELOW TO SHORTEN UP POST.

Code:
//
//  SaveViewController.m
//  Final
//
//  Created by wctc on 4/25/11.
//  Copyright 2011 WCTC. All rights reserved.
//

#import "SaveViewController.h"
#import "FinalViewController.h"

@implementation SaveViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


#pragma mark - PickerView Implamentation - assigning colums
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
   
    return 1;
}

#pragma mark - PickerView Implamentation - Loading # rows needed
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
   
    return [charSaveArray count];
}
#pragma mark - PickerView Implamentation - Filling Row Data
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [charSaveArray objectAtIndex:row];
}




#pragma mark - PickerView Implamentation - Delagation
// method to react to a picker view selection
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    charSaveMarker = row;
    //NSLog(@"%@",[arrayAnswers objectAtIndex:0]);
}





#pragma mark - View lifecycle

- (void)viewDidLoad

{  
    charData = [[CharData alloc]init ];
   
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}



- (IBAction)tapNewChar:(id)sender {
    [viewSplash addSubview:viewNewChar];
}

-(NSString*)PassNewCharName{
    return txtNewChar.text;
}

- (IBAction)tapCreateNewChar:(id)sender {
    [txtNewChar resignFirstResponder];
    if ([txtNewChar.text length]<=0) {
        UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"No Name Entered" message:@"No name was Given. A name is Required." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [theAlert show]; [theAlert release];
    }
    if([txtNewChar.text length]<=1){
        [finalViewController LoadHomeWorld];
    }
}
@end

WHAT HAPPENS HERE IS IN A VIEW CALLED createNewChar with a button(tapCreateNewChar) and a text box (txtNewChar). the finalViewController is an outlet linked to FinalViewController.
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
Am I missing something. I didn't see where you said what happens. Is there an error message, crash, or just nothing happens? What button are you specifically talking about and where is the code that it is connected to?

"my Problem Occurs when i click another button in a diffrent view from the SaveViewController, which calls a method from FinalViewController." I don't think that is considered to be normal. A view controller in iOS is used to take control of the whole screen. Calling a previous controller is possible but if you are dealing with a user interface item, you have to concerned what it is connected to, as in the previous controller, not the current one.

Although tempted to look at your code, I don't normally click on links random suggested by people I don't know.
 
OP
B
Joined
Apr 27, 2011
Messages
10
Reaction score
0
Points
1
reply

Code:
- (IBAction)tapCreateNewChar:(id)sender {
    [txtNewChar resignFirstResponder];
    if ([txtNewChar.text length]<=0) {
        UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"No Name Entered" message:@"No name was Given. A name is Required." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [theAlert show]; [theAlert release];
    }
    if([txtNewChar.text length]<=1){
        [finalViewController LoadHomeWorld];
    }
the line
[finalViewController LoadHomeWorld];
this method is not working in this view.

Am I missing something. I didn't see where you said what happens. Is there an error message, crash, or just nothing happens? What button are you specifically talking about and where is the code that it is connected to?

"my Problem Occurs when i click another button in a diffrent view from the SaveViewController, which calls a method from FinalViewController." I don't think that is considered to be normal. A view controller in iOS is used to take control of the whole screen. Calling a previous controller is possible but if you are dealing with a user interface item, you have to concerned what it is connected to, as in the previous controller, not the current one.

Although tempted to look at your code, I don't normally click on links random suggested by people I don't know.
 
Joined
Feb 25, 2009
Messages
2,112
Reaction score
71
Points
48
Your Mac's Specs
Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
I looked at all of your code..

It's coded in a style I don't personally prefer, but after reading it for a while and seeing what you are trying to accomplish these changes:

1) in SaveViewController.xib - delete the object in there that is a FinalViewController; it's not needed and creates an improper reference (it will instantiate a new FinalViewController rather then your FinalViewController you're attempting to work with).

2) In SaveViewController.m - in the method tapCreateNewChar change:
Code:
if([txtNewChar.text length]<=1){
        [finalViewController LoadHomeWorld];
    }

to

Code:
if([txtNewChar.text length]>=1){
        [finalViewController LoadHomeWorld];
    }

3) Open up FinalViewController.xib, right click on the ViewController-Save object, in the Outlets, link the FinalViewController to the File's Owner (which will tell it that the FinalViewController instance should be associated with its IVar)

I think that's all of the changes I made. appear to fix the problem. I'm attaching screen shots of the two changes in the xib files... I've also uploaded the screen I get to now after keying in a name (yes, that one button is off the screen so you'll need to adjust your nib a little...)

Screen shot 2011-04-27 at 10.38.59 PM.png

Screen shot 2011-04-27 at 10.34.17 PM.png

Screen shot 2011-04-27 at 10.34.06 PM.png
 
OP
B
Joined
Apr 27, 2011
Messages
10
Reaction score
0
Points
1
thank you

Thanks for the input i don't have access to xcode outside of class on Mondays and Wednesdays so ill def give all your input a go then and let you know.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top