Reputation: 31953
Is it feasible to change UITableView style to grouped from within implementation file, but the instance is already defined in storyboard?
So, I write the following code in ViewController.m, where tableView
is connected through storyboard by ctrl-dragging:
@interface ViewController()
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
However, when I tried to set in viewDidLoad
method, such as:
self.tableView.style = UITableViewStyleGrouped;
I got an error saying Assignment to readonly property
.
So I wonder whether it is feasible to set it from within implementation file.
I just found the way to set the attribute, but then I have to initialize the code entirely from scratch.
I also know that I can set it in Attribute Inspector, just like to know how I can set it from within code (but again, the variable is already defined, meaning I can't initialize, if I understand it correctly).
Also, why I got an error Assignment to readonly property
, despite my NOT defining readonly
in the @property
definition? (for your information even if I add readwrite
to the definition above I still got the same error.)
I use Xcode 5.
Thanks.
Upvotes: 0
Views: 854
Reputation: 130193
No. You can't change the style of a table view after initialization. When you specify the tables style in Interface Builder, you're specifying what style the table will be initialized with.
And as far as the error goes, it isn't referring to the property that you made for your table view, it's referring to the style
property that the UITableView
class declares publicly as read-only. The property is then redeclared privately as read-write so that it can be set in the initializer, but either way, you can't modify it.
Upvotes: 1