1

I have a UIViewController which open up a Camera, after doing the imagePickerController:didFinishPickingMediaWithInfo: a UITableView shall be shown.

Somehow the tableView delegation code is not triggered. A tableView is shown on my iPhone but with empty rows. Seems that just the IB Stuff is displayed without the code. But I cannot figure out what I missed.

How do I get the UITableView working?

MainStoryboard.storyboard

Camera View Controller Scene
----------------------------
  Camera View Controller
    View
      Image View // hooked up with .h
      Table View  // hooked up with .h
        Table View Cell - clocation

CameraViewController.h

#import <UIKit/UIKit.h>

@interface CameraViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *imageView; // hooked up with IB UIImageView
@property (strong, nonatomic) NSMutableArray *locations;
@property (strong, nonatomic) IBOutlet UITableView *tableView;  // hooked up with IB UITableView

@end

CameraViewController.m (Updated 20130725 with working solution)

#import "CameraViewController.h"

@interface CameraViewController ()

@end

@implementation CameraViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // self.locations = [[NSMutableArray alloc] init];  
    // is filled with content when photo is taken. Means has content when tableview shall be shown. 
    self.locations = @[ @"foo", @"bar" ]; // dummy setup for this thread

    // Do any additional setup after loading the view.
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            // select Photo
    } else {
        [self takePhoto];
    }

    [self initTableView];

} 

// [...] Camera Stuff


#pragma mark - table view things

-(void)initTableView {
    _tableView.dataSource = self;
    _tableView.delegate = self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.locations.count;  // a breakpoint is configured but never get hit...
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"clocation";

    // Not working in this case: 
    // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    // You have to use this one: 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [NSString stringWithFormat:@"Empty Cell %d", indexPath.row];

    return cell;
}
12
  • 2
    did u set the current view controller as a delegate to the table view ? Commented Jul 25, 2013 at 12:55
  • do you mean tableView.delegate = self;. I tried this in initWithNibName:bundle:, but it had no effect. I tried it like in NSElvis Answer Commented Jul 25, 2013 at 13:00
  • i assume you are loading it from a xib, so place it also in initWithCoder and make sure either initWithNibName:bundle or initWithCoder is called by placing a book mark or nslog. Commented Jul 25, 2013 at 13:07
  • its loaded from a scene in of the MainStoryboard.storyboard Commented Jul 25, 2013 at 13:11
  • Are you calling [tableView reloadData] when the UIImagePicker returns? Commented Jul 25, 2013 at 13:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.