-2

In a game that I am developing for iPhone, I would like to create a bingo board in which you can click one of the spots, and the camera opens. I have the camera part down, but I'm working on creating the board. I thought a Collection View with 25 items would work for the grid, but nothing is appearing on the screen when the app is running. Is there a better way to go about making the table?

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}

- (IBAction)cameraButtonClicked:(id)sender {
    if (![UIImagePickerController isSourceTypeAvailable:(UIImagePickerControllerSourceTypeCamera)]) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Camera Not Available" message:@"The camera feature isn't available on your device." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
        [alertView show];
    }else{
        //Show the Image Picker Controller Here
        UIImagePickerController * ipc = [[UIImagePickerController alloc] init];
        ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
        ipc.allowsEditing = NO;
        //Set the Delegate
        ipc.delegate = self;

        [self.navigationController presentViewController:ipc animated:YES completion:nil];
    }
}

#pragma mark ImagePicker Delegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:nil];

    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    self.imageView.image = image;
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end
MacBoss123541
  • 198
  • 1
  • 17
  • A collection view could be a solution. But this probably depends on what you really want to achieve. "Nothing is appearing on the screen" is quite hard to solve if you don't post your code. – johan Oct 12 '13 at 20:23
  • too broad & asking for code without showing what you tried: "Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance." – Daij-Djan Oct 12 '13 at 20:32

1 Answers1

1

I think your bingo board might be better implemented with multiple views or custom drawing. I personally would opt for custom drawing since I'm pretty comfortable there. Regarding your collection view idea, the only reason it may not be the best is because of less control over the inter-item spacing. In my experience, it is difficult to get the items to sit immediately between each other. I'll go down each potential route and give you my 2 cents:

1. Collection View

Do some research on laying out a perfectly aligned grid. You'll probably have to have a custom layout or change the collection view inset and / or minimumInteritemSpacing. See the following SO posts:

2. Manually-placed views

This technique will work if you know that you will only have a set number of bingo "slots" or "squares". You could create this in code, a storyboard, or a xib.

3. Custom Drawing / Layout

I would advocate for this technique because of its flexibility. You could pass the number of bingo tiles that you need and then either build UIButtons with a flat tile-like appearance or with the button style UIButtonTypeCustom. Another custom drawing way is to draw with CoreGraphics. However, this would not lend itself well to clean actions like from a UIButton and would require that you re-implement touch methods.

Conclusion

I would either try to go with the collection view if you can get the inter-item spacing worked out or I would go with calculated views laid out in code or if you have a fixed number of items then laid out in a storyboard or something.

Community
  • 1
  • 1
Christian Di Lorenzo
  • 3,562
  • 24
  • 33
  • I am no expert in C++ coding, which is why I went with a collection view. As you said, the spacing won't work, and I would like the data in the cells to display a randomly selected string from a list without repeat. I am assuming code is the best option for this, I don't know exactly what file it goes in, or how to really make a board for that matter. – MacBoss123541 Oct 12 '13 at 20:50
  • The language is actually Objective-C. If you post your code on [GitHub](https://github.com), I'll try to take a look at it and give you some recommendations / code. BTW, if you're new StackOverflow, you may want to take a look at the [about page](http://stackoverflow.com/about). If not, don't worry about it. – Christian Di Lorenzo Oct 13 '13 at 00:33
  • Thanks for all your help. I found a good tutorial on UICollectionViewControllers, and I integrated it with what I'm doing. http://www.youtube.com/watch?v=i9eFo2fRCdU I should search youtube a lot longer before I make posts here. – MacBoss123541 Oct 13 '13 at 02:32