UICollectionViewCell Not Displaying anything - ios6

I have a custom CollectionViewCell
#interface FBPicCell : UICollectionViewCell
#property (strong, nonatomic) IBOutlet UILabel *picby;
In my code in viewDidLoad I have
[self.fbpiccollectionView registerClass:[FBPicCell class] forCellWithReuseIdentifier:#"fbpiccell"];
and in cellForItemAtIndexPath function
FBPicCell *cell = [cv dequeueReusableCellWithReuseIdentifier:#"fbpiccell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
[cell.picby setText:#"Pavan"];
[cell.picby setTextColor:[UIColor redColor]];
But I don't see anything, just the white border. Not sure where i am messing things up. Any pointer would be helpful.

I had the same problem along with registring your call
register the nib as well as-
[collectionView registerNib:[UINib nibWithNibName:#"cellname" bundle:nil] forCellWithReuseIdentifier:#"cellname"];
This worked for me
Regards

Related

How to create a border for SCNNode to indicate its selection in iOS 11 ARKit-Scenekit?

How to draw a border to highlight a SCNNode and indicate to user that the node is selected?
In my project user can place multiple virtual objects and user can select any object anytime. Upon selection i should show the user highlighted 3D object. Is there a way to directly achieve this or draw a border over SCNNode?
You need to add a tap gesture recognizer to the sceneView.
// add a tap gesture recognizer
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
scnView.addGestureRecognizer(tapGesture)
Then, handle the tap and highlight the node:
#objc
func handleTap(_ gestureRecognize: UIGestureRecognizer) {
// retrieve the SCNView
let scnView = self.view as! SCNView
// check what nodes are tapped
let p = gestureRecognize.location(in: scnView)
let hitResults = scnView.hitTest(p, options: [:])
// check that we clicked on at least one object
if hitResults.count > 0 {
// retrieved the first clicked object
let result = hitResults[0]
// get its material
let material = result.node.geometry!.firstMaterial!
// highlight it
SCNTransaction.begin()
SCNTransaction.animationDuration = 0.5
// on completion - unhighlight
SCNTransaction.completionBlock = {
SCNTransaction.begin()
SCNTransaction.animationDuration = 0.5
material.emission.contents = UIColor.black
SCNTransaction.commit()
}
material.emission.contents = UIColor.red
SCNTransaction.commit()
}
}
The snippet above highlights the whole node. You'd have to adjust it to highlight the borders only, if that's what you're looking for.
Disclaimer:
This code was taken directly from Xcode's template code created when opening a new game (SceneKit) project.

Getting the Tag Number of Touched Object

I have a button. Every time the user clicks on it, the application will instantiate the UIImageView (imageview), assigning a unique number to its tag.
- (IBAction)buttonClicked:(id)sender {
imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 240)];
NSUInteger currentag = [self UniqueNum]; // Assigning a unique number to the tag variable
[self.view addSubview:imageview];
imageview.backgroundColor = [UIColor blueColor];
imageview.userInteractionEnabled = YES;
imageview.tag = currentag;
}
My goal is to get the tag number of the UIImageView copy that the user touches. With the following code, what I actually get is the tag number of the UIImageView copy that the application last created. How can I improve it so that the application will point to the tag number of the touched object?
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [[event allTouches] anyObject];
if([touch view] == imageview) {
NSLog(#"Tag: %i",imageview.tag);
}
}
Thank you for your help.
I'd recommend using UIButtons with custom images here rather than UIImageViews if you need interaction.
Add this when you add the button:
[imageview addTarget:self action:#selector(someMethod:) forControlEvents:UIControlEventAllTouchEvents];
And then just cast the sender in someMethod (your declaration) to UIView to get its tag.
BTW, the method signature of someMethod goes something like this:
-(void) someMethod:(id)sender
You can optionally also add an event parameter, but that doesn't seem to be needed here.

Menu Button in Cocos2d

Im trying to make the play button on the main menu of my game in Cocos2d which is an image file. I set up the sprite as playButton with the image Play Button.png. When I ran the app it gave me an error that the "itemFromNormalSprite:selectedSprite:target:selector." is deprecated. Anybody have a solution to this problem? Here is my code:
CCMenuItem *playGameButton = [CCMenuItemSprite itemFromNormalSprite:playButton selectedSprite:playButton target:self selector:#selector(buttonTapped:)];
CCMenu *menu = [CCMenu menuWithItems:playGameButton, nil];
menu.position = ccp(size.width/2, size.height/1.5);
[self addChild:menu z:5];
CCMenuItem *playGameButton = [CCMenuItemImage itemFromNormalImage:playButton selectedImage:playButton disabledImage:disabledPlayButton target:self selector:#selector(buttonTapped:)];
CCMenu *menu = [CCMenu menuWithItems:playGameButton, nil];
menu.position = ccp(size.width/2, size.height/1.5);
[self addChild:menu z:5];

How to create an object of custom class in iphone?

I want to create an object of my class Category. I am new in iphone development and do not know how to do it.
Its my class .h file
Category.h
#interface Category : NSObject
#property (nonatomic, retain) NSString *uid;
#property (nonatomic, retain) NSString *title;
#end
in java it can be done as.
Category category = new Category();
In Objective-c we create object like this:
Category * categoryObject = [[Category alloc] init];
Now you can insert data like below:
categoryObject. uid=#"2356-4fr5-ok8u-52o8-85ki-km76-l5bt-09ij-kf65-8ij6";
categoryObject. title=#"Sample Project";
Enjoy Coding
Category *category = [Category alloc]init];
import "Category.h" in .h file
Now we have allocate memory for that by writing like this
Category * categoryObj = [[Category alloc] init];
now we can use that object where you want it like this
categoryObj.uid = #"your data";
categoryObj.title = #"your data";
I hope this will help you

custom right bar button item in ios6 is not transparent

i am creating a custom right bar button item for my navbar using the following code :
// create a toolbar
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 50, 44.01)];
// create the array to hold the button, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:1];
// create a toolbar item with image
NSString* pathToSettingsResourceFile = [[NSBundle mainBundle] pathForResource:#"19-gear" ofType:#"png"];
UIImage* settingsImage = [[[UIImage alloc] initWithContentsOfFile:pathToSettingsResourceFile] autorelease];
settings = [[UIBarButtonItem alloc]initWithImage:settingsImage style:UIBarButtonItemStylePlain target:self action:#selector(showSettings:)];
settings.enabled = FALSE;
// add button to toolbar
[buttons addObject:settings];
[tools setItems:buttons animated:NO];
[buttons release];
// add toolbar as a right bar button item
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:tools] autorelease];
[tools release];
until ios 6 this works as expected, from ios 6 i am getting this weird rectangle background
and adding
tools.opaque = NO;
tools.backgroundColor = [UIColor clearColor];
doesn't help,
please help me get rid of this background
Thanks in advance,
Amit
I know this is an old thread, but I had the same issue, and thought you might be interested in what I discovered.
A work-around is available in this thread (the answer by jd, not the "accepted" answer).
You should be able to get the behavior you want with this code:
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
[tools setBackgroundImage:maskedImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
Although this works, I am not convinced that it is the correct way to do it, so I started a new thread here in case anyone knows the secret code for making a UIToolbar containing rectangle behave as a transparent object should.

Resources