I am setting the font property of a label using the fontWithSize: method and while it works fine in iOS 5, iOS 4.3 I am getting an exc_bad_access error. Here is my code:
UILabel *headerText = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width - 10, 42)];
headerText.text = [tableView.dataSource tableView:tableView titleForHeaderInSection:section];
headerText.font = [[UIFont alloc] fontWithSize:8];
Again, this code works perfectly in iOS 5, but crashes as the last line in 4.3. I checked the Apple API docs and fontWithSize: as well as the font property of a UILabel have both been around since iOS 2. Is there anything else wrong here?
If you use alloc to initial, the method usually begins with
init.fontWithSize :is not used to initial.It means that you should call it using an existing font instance.
For example:
But if you want to initial an instance, you need call the class method or instance method beginning with init.