pass selected object to second viewcontroller and display in uilabel - core-data

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.

Related

How to overlay MKPolyline on top of different maps

So I draw a MKPolyline with the users updated CLLocationCoordinates as per usual. When my quits and starts again, all of the past points are loaded onto the mapview to be displayed with
routeLine = [MKPolyline polylineWithCoordinates:clCoordinates count:numberOfSteps];
[_mapView addOverlay:routeLine];
and in MKOverlayRenderer method I have
if ([overlay isKindOfClass:[MKPolyline class]])
{
MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithPolyline:overlay];
renderer.strokeColor = [[UIColor whiteColor] colorWithAlphaComponent:0.7];
renderer.lineWidth = 3;
return renderer;
}
This all works a treat, but problems arise when I change the type of map with
[self resetMapViewAndRasterOverlayDefaults];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
_rasterOverlay = [[MBXRasterTileOverlay alloc] initWithMapID:#"jonobolitho.j834jdml"];
_rasterOverlay.delegate = self;
[_mapView addOverlay:_rasterOverlay];
Note, I have the resetMapViewAndRasterOverlayDefaults helper method
// Reset the MKMapView to some reasonable defaults.
//
_mapView.mapType = MKMapTypeStandard;
_mapView.zoomEnabled = YES;
[_mapView removeAnnotations:_rasterOverlay.markers];
[_mapView removeOverlay:_rasterOverlay];
[_rasterOverlay invalidateAndCancel];
I am using MBXMapKit to display the maps. The maps display correctly, but the polyline isn't shown on top of the map. The map just loads over the top of my polyline (routeLine). I know this because in between the tiles of the new map I can see the routeLine underneath.
So basically is there a way to load the MKPolyline but always keep it on the top layer of the map, even if it changes?
Instead of:
[_mapView addOverlay:_rasterOverlay];
You want:
[_mapView insertOverlay:_rasterOverlay belowOverlay:routeLine];
Or something similar. Overlays have an order.

Custom uitabeviewcells blank when scrolling

I have two custom UITableViewCells I am trying to populate from an array that I am pulling from CoreData using MagicalRecord. The first three rows of data appear (the cells that are initially visible when the view loads) but when I scroll none of the cells below have any data populated into them. Also, when I scroll up the cells that initially displayed data are now blank. So it seems to be happening when any cell gets reused. I have been racking my brain and coming up empty on all my attempts to solve the problem. Here is mycellForRowAtIndexPath code.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Explore *explore = [self.exploreCellData objectAtIndex:[indexPath row]];
if ([explore.belief_id isEqualToString:#"0"]) {
ExploreVoteCell *cell = (ExploreVoteCell *) [tableView dequeueReusableCellWithIdentifier:#"ExploreVote" forIndexPath:indexPath];
[cell.topicTitle setText:[explore topic_title]];
[cell.votesCount setText:[explore calc_totalVotes]];
[cell.timeDayCount setText:[explore day_difference]];
return cell;
} else {
ExploreBeliefCell *cell = (ExploreBeliefCell *) [tableView dequeueReusableCellWithIdentifier:#"ExploreBelief" forIndexPath:indexPath];
[cell.topicTitle setText:[explore topic_title]];
return cell;
}}
When I count the number of records in the array (for the number of rows) or NSLog some data elements when the table view loads the data is there. However, when I scroll the NSLog I set up inside the 'cellForRowAtIndexPath` method starts returning a null value once the scroll needs to start reusing cells.
I am new to using both MagicalRecords and AFNetworking so perhaps I am not be handling those correctly. Here is how I am pulling the data from CoreData into my NSMutableArray
- (void) fetchData {
self.exploreCellData = [NSMutableArray arrayWithArray:[Explore MR_findAllSortedBy:#"calc_totalVotes" ascending:YES]];}
Any help be greatly appreciated!
try using :
[tableView registerClass:[YOURCUSTOMCELL class] forCellReuseIdentifier:#"CUSTOMIDENTIFIER"];
in forexample viewDidLoad
and in cellForRowAtIndexPath:
-(UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ListCell * cell = [tableView dequeueReusableCellWithIdentifier:#"CUSTOMIDENTIFIER"];
return cell
}

Cocos 2d CCmenu not appearing

I have recently coded in a menu item, the "Game Over" Label appears but the menu item "Restart" isn't. I have no idea why?
Can anyone help, here is whats in my method !
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCLabelTTF *label = [CCLabelTTF labelWithString:#"Game Over"
fontName:#"Marker Felt"
fontSize:64];
label.color = ccRED;
label.position = ccp(winSize.width*0.5, winSize.height*0.75);
[self addChild:label];
CCMenuItem *item = [CCMenuItemFont itemWithString:#"Restart"
target:self
selector:#selector(restartGame)];
CCMenu *menu = [CCMenu menuWithItems:item, nil];
[menu alignItemsVertically];
[self addChild:menu];
try this code:
menu.position = ccp(winSize.width/2, winSize.height/2);
set the specific position.

MonoTouch - changing DetailTextLabel text color is causing a NullReferenceException error

I am trying to finish up a custom cell for my tables using monotouch.dialog, and have nearly everything sorted out, except for my cell's detail text label colour.
I am overriding GetCell to customise my EntryElement cell like this:
public class CustomStyledEntryElementPlain : MonoTouch.Dialog.EntryElement
{
public CustomStyledEntryElementPlain (string _caption, string _value) : base(string.Empty,string.Empty,string.Empty,false)
{
KeyboardType = UIKeyboardType.Default;
Value = _value;
ReturnKeyType = UIReturnKeyType.Done;
Caption = _caption;
}
public override UITableViewCell GetCell(UITableView tableView) {
var cell = base.GetCell(tableView);
cell.BackgroundColor = Resources.XDarkGrayColor;
cell.TextLabel.TextColor = Resources.XWhiteColor;
cell.BackgroundView = new UIView (RectangleF.Empty);
cell.DetailTextLabel.TextColor = UIColor.White; //this line causes the error
return cell;
}
}
I then create the elements like so:
new CustomSection ("Testing"){
new CustomStyledEntryElementPlain("Test","Test1"),
new CustomStyledEntryElementPlain("Test","Test2")
},
However, on displaying the table, I get the error: "System.NullReferenceException has been thrown Object reference not set to an instance of an object"
I could have sworn when I initially prototyped this that I had the DetailTextLabel text color working! Commenting out the change of course results in my table and cell displaying just fine, albeit with black text (which I want to change to white!)
Has anyone got any idea as to why I am getting this?
The DetailTextLabel property in the UITableViewCell is only available if the Cell has a UITableViewCellStyle that supports it. From the UITableViewCell documentation for the DetailTextLabel property:
UITableViewCell automatically creates the secondary (detail) label if the cell is created with a MonoTouch.UIKit.UITableViewCellStyle that supports a detail label.
If the cell's style doesn't support a detail label, this property returns null.
Check the documentation for UITableViewCellStyle to find out which styles support this property.

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...

Resources