I am trying to call my view in the second view controller with a new set of values to be changed in the first view controller. i am using pointers to get my first viewcontroller's view (used a property that points to firstview controller) but i am not seeing any changes in the view. ideas are appreciated. Thank you
//secondviewcontroller.m
#import "SecondViewController.h"
#import "FirstViewController.h"
#import "Tab.h"
#import "AppDelegate.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
@synthesize changeSizeSlider;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"second", @"second");
self.tabBarItem.image = [UIImage imageNamed:@"second"];
}
return self;
}
- (IBAction)changeSizeSlider:(UISlider *)sender
{
// Change label to match slider's value
label1.text = [NSString stringWithFormat:@"%g", [changeSize value]];
// Var for changing size
CGFloat changeSizeCont = [changeSize value];
NSLog(@"changeSizeCont = %f", changeSizeCont);
((Tab *)vc.view).rect_width = changeSizeCont;
((Tab *)vc.view).rect_height = changeSizeCont;
// The values here are displayed but i think the view is not reloaded with the nw values
NSLog(@"Current values for VC's view properties:");
NSLog(@"rect_width = %f", ((Tab *)vc.view).rect_width);
NSLog(@"rect_height = %f", ((Tab *)vc.view).rect_height);
}
Calling the firstviewcontroller's view object vc by calling its property in //secondviewcontroller.h
@property FirstViewController *vc;
//firstviewcontroller.m
#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)viewWillAppear:(BOOL)animated
{
//NSLog(@">>> %@", NSStringFromSelector(_cmd) );
self.title = NSLocalizedString(@"First", @"First");
self.tabBarItem.image = [UIImage imageNamed:@"first"];
// Get timer
NSTimer *timer = [NSTimer timerWithTimeInterval: 0.5
target: self.view
selector: @selector(setNeedsDisplay)
userInfo: nil
repeats: YES];
// Get runloop, add timer to runloop
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:timer forMode: NSDefaultRunLoopMode];
}
I have the functions that draws the rectangles written in a class.
//appdelegate.m #import "TabAppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "Tab.h"
@implementation TabAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
time_t seed = time(0);
srandom((int)seed);
CGRect bounds = [self.window bounds];
Tab *view = [[Tab alloc] initWithFrame:bounds];
view.backgroundColor = [UIColor whiteColor];
FirstViewController *vc = [[FirstViewController alloc] init];
[vc setView: view];
SecondViewController *vc2 = [[SecondViewController alloc] init];
//[vc2 setView: view];
vc2.vc = vc;
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[vc, vc2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Tab.m has the draw functions that will appear in the firstview and secondview has a nib that handles the changes in firstviewcontroller.
I pretty much think i am not wrong anywhere, i spent almost one week without figuring out this issue. Appreciate your time guys.