How to pass NSMutable arrays to table view? - nsmutablearray

I am having three buttons in a view. and three actions for three buttons. In the first view i have declared three buttons and three actions for that three buttons.
In the next view i have taken table view. And I have taken three mutable arrays.
If the first button is pressed the first mutable array items is to be passed into tableview.
If the second button is pressed the second mutable array items is to be passed into tableview.
If the third button is pressed the third mutable array items is to be passed into tableview.
Can anybody give me the code.

Its simple..you just need to change the datasource of the tableView.... in cellForRowAtindexPath method whatever array you are passing just change that on buttonClick event and reload the tableView
Hope this will help you.
Edit Added : for NSNotification
FirstView.m
-(void)buttonAction{
[[NSNotificationCenter defaultCenter] postNotificationName: #"changeArray" object:yourArray userInfo:nil];
}
SecondView.m
-(void)ViewDidLoad{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receiveTestNotification:) name:#"changeArray" object:nil];
}
-(void)receiveTestNotification:(NSNotification)iNotification{
NSMutableArray *myArray = [iNotification object];
//do your changes.
}

Related

pass selected object to second viewcontroller and display in uilabel

I'm attempting to pass a selected item in a tableview to be displayed in a UILabel on a second viewcontroller. Currently I can segue to the second viewcontroller but nothing displays. I've also attempted to create an instance of the selected item for it to be used as reference in a predicate. The segue I have is:
([segue.identifier isEqualToString:#"showResults"]); {
ResultsVC *rvc = (ResultsVC *) [segue destinationViewController];
NSIndexPath *indexPath = [self.searchTV indexPathForSelectedRow];
self.selectedItem = [_fetchedResultsController objectAtIndexPath:indexPath];
rvc.item = self.selectedItem;
rvc.managedObjectContext = self.managedObjectContext;
and in cell for row at index path:
Item *item = [_fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = item.itemName;
and in the second viewcontroller call the label to display the item:
self.itemNameLabel.text = _selectedItem.itemName;
I have tried self.selectedItem.itemName and other iterations with no luck.
What have I missed to get the UILabel to display data?
Thanks for the help!
Use NSUserDefaults to save the selected text and then retrieve it from the other view.
See this post to a similar question.

TabBar Segue when selecting row in table view controller

I already have a segue set in place in my table view controller for an add button press. Now I want to have another segue for when the user selects on the newly added object. My code looks like this so far:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Add Vehicle Segue"])
{
NSLog(#"Setting RootViewController as a delegate of AddViewController");
AddViewController *addViewController = segue.destinationViewController;
addViewController.delegate = self;
addViewController.managedObjectContext = self.managedObjectContext;
}
I think I will need to add an else if next to take care of the tab bar segue but don't know how to do that.
Also the tab bar view is just there to show the two tabs so I don't believe I will preform the segue with the reference to core data.
Thanks in advance.!
My storyboard flow
If you do not want to pass value to the next view controller or do any actions that need to done before performing the segue, but just display the tab bar then you don't need to add anything in the prepareForSegue:sender: method. If you do have to do something when performing the segue add and else condition as there is only two segues and write your code inside the else block.

Cocos2d: is there a way to access to a CCMenu child?

I am using the following code:
CCMenuItemFont *controllerItem = [CCMenuItemFont itemFromString:#"Analog" target:self selector:#selector(controllerToggle)];
CCMenu *controllerTypeMenu = [CCMenu menuWithItems:controllerItem, nil];
[controllerTypeMenu alignItemsVerticallyWithPadding:30.0f];
controllerTypeMenu.position = CGPointMake(160.0f, 240.0f);
[self addChild:controllerTypeMenu z:0 tag:ControllerMenu];
}
-(void) controllerToggle
{
CCMenuItemFont *controllerItem = [self getChildByTag:888];
NSString * text = [NSString stringWithFormat: #"switching.. %f", CCRANDOM_0_1()];
[controllerItem setString:text];
}
In controllerToggle I would like to access to controllerItem and change the String to another value. Is this possible? I checked and CCMenu adds as child the CCMenuItems based the array order. But that's not an elegant solution. For the same reason I cannot add the CCMenuItem to the Scene as it will give me "child already added error". So I feel I should write my own "switch" button but I wonder if there is already something out there..
Any help?? Thanks!
you can declare needed menu item as class member. In this way you will be able to get access to it whenever you want
There is already CCMenuItemToogle which is used to switching the title or image of any menuitem on click event.Instead of taking CCMenuItem you can use CCMenuItemToggle..
Here is a sample code
CCmenuItemToggle *cam=[CCMenuItemToggle itemWithTarget:self selector:#selector(openCameraController) items:cameraOn,cameraOff, nil];
where cameraOn and cameraOff are two simple CCMenuItemImage which is added in CCMenuItemToggle and further this CCmenuItemToggle is added in a menu.
Now on every click of CCMenuItemToggle there will be a cameraOn and cameraOff state for same menuitem.
Hope this will help...

Is a timer mandatory for drawing OPENGL ES

I have a method called startAnimation:
-(void)startAnimation{
1: self.animationTimer=[NSTimer scheduledTimerWithTimeInterval:1/60
target:self selector:#selector(gameLoop)
userInfo:nil repeats:YES];
2: //[self gameLoop]
{
The gameLoop method is like this:
-(void)gameLoop{
[self updateModel];
[self render]
{
Now, a very strange thing happens. If I comment the line 1 and uncomment the line 2 in startAnimation method I will not get the objects rendered to my screen. I thought rendering might require continuously calling the gameLoop metod. But even if I set the timer to not repeat (so repats:NO) objects are drawn. It means calling the gameLoop method just once, but from an NStimer object is enough. But if I call the gameLoop method manually I do not get the objects drawn. I tried calling the method inside a loop which executes 100 times. It did not help either. Is there something special with the timers in regards with OPENGL?Sorry for the question if it's too immature.
It´s been some time since you asked but the problem there is that the time interval is set to 1/60, which is 0 because it´s using the integer division. You should use 1.0/60.0 instead.
A timer is not needed for OpenGL ES. For my drawing app the render method is called everytime the user touches the screen.
However, for games most developers use CADisplayLink to call the render or gameloop method instead of NSTimer, as CADisplayLink will call the render method each time the screen refreshes.
Setting up a CADisplayLink is done like the example below.
- (void)setupDisplayLink {
//this sets up the game loop to be called once each time the screen refreshes
CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:#selector(gameLoop:)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
Then the gameLoop should be setup as:
- (void)gameLoop:(CADisplayLink *)displayLink {
[self updateModel];
[self render];
}

MKMap annotation selection

I want to check when he user presses the annotation (the bubble on top of the pin). I tried the following :
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{}
but it fires up when i press the pin. How can i check when the user actually presses on the annotation bubble?
You can first put a right accessory button and set an separate action for it as such:
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
you can implement the showDetails method with the function that you like

Resources