objective c - Adding UITableView to existing UIViewController -
i have uiviewcontroller
open camera, after doing imagepickercontroller:didfinishpickingmediawithinfo:
uitableview
shall shown.
somehow tableview delegation code not triggered. tableview shown on iphone empty rows. seems ib stuff displayed without code. cannot figure out missed.
how uitableview
working?
mainstoryboard.storyboard
camera view controller scene ---------------------------- camera view controller view image view // hooked .h table view // hooked .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 ib uiimageview @property (strong, nonatomic) nsmutablearray *locations; @property (strong, nonatomic) iboutlet uitableview *tableview; // hooked ib uitableview @end
cameraviewcontroller.m (updated 20130725 working solution)
#import "cameraviewcontroller.h" @interface cameraviewcontroller () @end @implementation cameraviewcontroller - (void)viewdidload { [super viewdidload]; // self.locations = [[nsmutablearray alloc] init]; // filled content when photo taken. means has content when tableview shall shown. self.locations = @[ @"foo", @"bar" ]; // dummy setup thread // additional setup after loading 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; // breakpoint configured never hit... } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"clocation"; // not working in case: // uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath]; // have use 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; }
Comments
Post a Comment