Currently, I have two tabs, one with a button and text field, the second with a label, when a user enters something into the text field and presses the button, it should update the label, no the case. It ends the app, with no errors, exceptions or anything.
Starting with the three headers,
From: View1Controller.h
#import <UIKit/UIKit.h>
#import "HardCodeTabsAppDelegate.h"
@class HardCodeTabsAppDelegate;
@interface View1Controller : UIViewController {
UITextField *textField;
UIButton *cmdButton;
UIView *myView;
HardCodeTabsAppDelegate *delegateRef; //communication between windows
}
@property(nonatomic, assign) UITextField *textField;
@property(nonatomic, assign) UIButton *cmdButton;
@property(nonatomic, assign) UIView *myView;
@property(nonatomic, assign) HardCodeTabsAppDelegate *delegateRef;
@end
From: View2Controller.h
#import <UIKit/UIKit.h>
@interface View2Controller : UIViewController {
UILabel *label;
UIView *myView;
}
@property(nonatomic, assign) UILabel *label;
@property(nonatomic, assign) UIView *myView;
@end
From: HardCodeTabsAppDeligate.h
#import <UIKit/UIKit.h>
#import "View1Controller.h"
#import "View2Controller.h"
@class TabBarViewController;
@class View1Controller;
@class View2Controller;
@interface HardCodeTabsAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
View1Controller *view1Controller;
View2Controller *view2Controller;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, assign) UITabBarController *tabBarController;
@property (nonatomic, assign) View1Controller *view1Controller;
@property (nonatomic, assign) View2Controller *view2Controller;
@end
From: View1Controller.m
#import "View1Controller.h"
@implementation View1Controller
@synthesize myView;
@synthesize cmdButton;
@synthesize textField;
@synthesize delegateRef;
- (id)init //Should this have been in a different method? Or is okay as its own?
{
if (self = [super init])
{
//initialaization codez
self.title = @"Text and Button"; //tab bar title
CGRect cgRct = CGRectMake(0, 0, 320, 480);//size and position
myView = [[UIView alloc] initWithFrame:cgRct];
myView.autoresizesSubviews = YES;
self.view = myView;
cmdButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect]retain];
cmdButton.frame = CGRectMake(100, 100, 100, 50);
[cmdButton setTitle:@"Click Me Now!!" forState:UIControlStateNormal];
cmdButton.backgroundColor = [UIColor clearColor];
[cmdButton addTarget:self action:@selector(ButtonPress) forControlEvents:UIControlEventTouchUpInside];
cmdButton.adjustsImageWhenHighlighted = YES;
cgRct = CGRectMake(60, 170, 200, 50);
textField = [[UITextField alloc] initWithFrame:cgRct];
textField.text = @"Enter text here";
textField.borderStyle = UITextBorderStyleBezel;
[self.view addSubview:cmdButton];
[self.view addSubview:textField];
}
return self;
}
-(void)ButtonPress:(id)sender //I think that the problem lies here somewhere
{
[self.textField resignFirstResponder];
self.delegateRef.view2Controller.label.text = self.textField.text;
}
From: View2Controller.m
@implementation View2Controller
@synthesize label;
@synthesize myView;
- (id)init
{
if (self = [super init]) //Same as before, its own? Or is this okay?
{
self.title = @"The Label";
CGRect cgRct = CGRectMake(0, 0, 320, 480);
myView = [[UIView alloc] initWithFrame:cgRct];
myView.autoresizesSubviews = YES;
self.view = myView;
cgRct = CGRectMake(60, 170, 200, 50);
label = [[UILabel alloc] initWithFrame:cgRct];
label.text = @"Test";
[self.view addSubview:label];
}
return self;
}
From: HardCodeTabsAppDeligate.m
@implementation HardCodeTabsAppDelegate
@synthesize window;
@synthesize view1Controller;
@synthesize view2Controller;
@synthesize tabBarController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
tabBarController = [[UITabBarController alloc] init];
view1Controller = [[View1Controller alloc] init];
view2Controller = [[View2Controller alloc] init];
view1Controller.delegateRef = self;
tabBarController.viewControllers = [NSArray arrayWithObjects:view1Controller, view2Controller, nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}
I've looked through all of the code many times, but no problems show up, thank you for your help.
This post has been edited by adgarci: 05 April 2010 - 07:06 PM

New Topic/Question
Reply



MultiQuote




|