开发者

Reloading tableView when subclassed causing crash

Hey guys! I have some problems reloading my tableView. I have subclasses my tableView, with a class called RadioTable. I have also subclasses my TableViewCells, but thats not important here.

I need to point out that i'm pretty new, and built my subclass from some tutorials and stuff.

First of all, here is the error message i'm getting when i try to reload my data. I am reloading it with [self.tableView reloadData].

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "MainView" nib but didn't get a UITableView.'

Okay, so the problem is pretty clear. The view(my nib-file) does not have any tableView's connected to the Files Owner. And thats what i tried to solve. I tried to add a IBOutlet in my subclass, and setting the tableView-property there.

(My tableView-subclass is inherited from UITableView, just so thats clear)

Here is my init-code:

- (id)initWithStyle:(UITableViewStyle)style {

 if ((self = [super initWithStyle:style])){
  RadioTable *aTableView = [[RadioTable alloc] initWithFrame:self.tableView.frame style:style];
  [aTableView setDelegate:self];
  [aTableView setDataSource:self];
  [aTableView setSwipeDe开发者_StackOverflow社区legate:self];
  [aTableView setRowHeight:54];

     [self setTableView:aTableView];
        [self.tableView setScrollEnabled:NO];
        [self.tableView setRowHeight:80];
        [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
        [self.tableView setSeparatorColor:[UIColor lightGrayColor]];
  [aTableView release];

 }

 return self;
}

The tableView works fine when i launch the app, it works perfect. But the problem occours when i try to reload it.


I'm not sure if this will solve your problem, but don't create your view controller's view in its init method. Instead, override loadView and create the table view in that method. And assign the table not only to the tableView property but also to the view controller's view property.

See the documentation for loadView and viewDidLoad for more info.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜