I have main view controller that contain an NSMutableArray. I want to open a subview with stepper to change quantity of a product included in that NSMutableArray.
How can I access to the NSMutableArray from subview and change an object inside it?
In your SubView class make a property of class NSMutableArray as
#interface SubViewClass : UIView
#property (strong, nonatomic) NSMutableArray *array;
#end
Now in your main view controller when calling this SubView you can assign your NSMutableArray instance into SubView array;
subViewInstance.array = mainControllerArray;
Now you can modify this array the way you want in your SubView Class.
Create a modal class. Then assign all the data to it and access that modal class from your other subview class.
Related
ClassA *a = [[ClassA alloc] initWithNibName:#"classA" bundle:nil];
a.viewInClassA.hidden = NO;
When i Run this code, the a.viewInClassA.hidden = NO do not make any effect PLEASE HELP
This is happen because you are making new class you not taking reference. So make property of that class and pass reference of class c in another class and then you can do hide using that property
In ClassA for example you have tableview.
Put this in ClassA.h file
#property (weak, nonatomic) IBOutlet UITableView *tableview;
From classB.h file make property of classA
#property (Strong, nonatomic) classA *classAObject;
And form classb.m where you want to hide table view write this
self.classAObject.tableview.hidden = YES;
when you open classB pass classA reference
ClassB *classB = [[ClassB alloc] initWithNibName:#"ClassB" bundle:nil];
classB.classAObject = self;
[self.navigationController pushViewController:classB animated:YES];
Don't try and manipulate another view controllers views. It's a violation of the principle of encapsulation. It's bad design, and sometimes it fails, as in your case.
Instead, add a property to your ClassA view controller that tells whether or not your view should be hidden. In your ClassA view controller's viewWillAppear read the property and use it to hide or show the view.
I have a sequencer with each track that has buttons as an outlet collection. The code all works fine in it's own view controller however I want to transfer all the methods to a singleton so that I can control the playback from other views.
for instance I have
#property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *trackOneOutletCollection;
However I have methods which act on the alpha and tags of each button; the methods contain these vales which I don't know how to access from the singleton. I thought the singleton was where I store all the data and then call it from the class file view controller?
You can use Inheritance concept to achieve this functionality.you need to create one ParentViewController that hold IBOutletCollection property. and rest of all View Controller is child of ParentViewController. then you can access IBOutletCollection in other view ontroller. like this way.
ParentViewController:-
#interface ParentViewController : UIViewController
#property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *trackOneOutletCollection;
#end
ChildViewController;-
#interface YourViewController : ParentViewController
#end
.m file
#implementation YourViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"trackOneOutletCollection = %#"self.trackOneOutletCollection);
}
#end
I can only access the id of my outlet collection and an id does not have a hidden property
This is my outlet collection
#property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *hearts;
and this is when I try to call it, and change it to hidden.
[self.hearts objectAtIndex:0].hidden =YES;
I can not because objectAtIndex only returns an id
Thanks for any help
You can try enumerating the objects in the collection, using the type you expect (eg, for (UIView *heartView in self.hearts)) or first cast the objectAtIndex:0 and then set the hidden property.
I have a single view application that has a subview. That subview contains a form that includes e-mail textfield and password textfield. I need to set the delegates to those textfields to the "global" this.
Everything is written code, nothing on the storyboard.
How can I pass my ApplicationViewController to the textfields?
Add a #property for your viewController and pass that to your UIView class.
In your UIViewClass.h
#property (nonatomic, strong) UIViewController *yourViewController;
Then pass the current viewController to your UIView when you create it.
UIView *yourView = [UIView new];
yourView.yourViewController = self;
Then you can access your viewController directly from in your UIView class.
yourTextField.delegate = _yourViewController;
I'm getting a bit confused with UIViews recently, I have been using them fine up until this point and they are just refusing to be compliant!
I have a UIViewController, and this contains 5 different views. I have created IBOutlets for these views as I am wanting to swap them at runtime:
IBOutlet UIView *view1;
IBOutlet UIView *view2;
IBOutlet UIView *view3;
IBOutlet UIView *view4;
IBOutlet UIView *view5;
To make them easier to maintain I decided to keep them all within an array, called viewArray. Now I am trying to add the views to the array as follows:
viewArray = [NSArray arrayWithObjects:view1, view2, view3, view4, nil];
This is being called in the init function of my UIViewController class. I have linked up all the IBOutlets to their relevant views in the xib / interface file, but they do not appear to be initialized. Upon further debugging it looks like the views aren't initialized until after the init function is called?
So how can I create an array of these objects? I will need to select the relevant view before the view itself is shown, therefore viewDidLoad is not an option.
I know that you can grab the tags of things and implicitly set them using:
imageExample = (UIImageView *)[self.view viewWithTag:100];
But can this be used to find views, as surely it will be searching for the tags within the originally initialized view (view1)?
Thanks for any help in advanced,
Kind Regards,
Elliott
You can initialize the viewArray lazily, for the price of having to use self.viewArray instead of unqualified viewArray.
Here is how you can do it:
In the .h file:
NSArray* _viewArray;
#property (nonatomic, readonly) NSArray *viewArray;
In the .m file:
-(NSArray*) viewArray {
if (!_viewArray) {
_viewArray = [NSArray arrayWithObjects:view1, view2, view3, view4, nil];
}
return _viewArray;
}