开发者

iOS - setting outlets on a ViewController being used as a UITableView header

开发者 https://www.devze.com 2023-01-22 06:18 出处:网络
I\'m using custom headers for my tableview... - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

I'm using custom headers for my tableview...

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
   CustomHeaderController *header = [[CustomHeaderController alloc]
    initWithNibName:@"TableHeader" bundle:nil];

  header.title.text = @"Test";

  return header.view;
}

The title label is never set though. I even tried creating a viewWillAppear method and setting it there, but that didn't work. My outlets are set up too!

Thanks!

SOLUTION: View wasn't load on the 开发者_JAVA技巧return header.view call. Call header.view or add a viewDidLoad method to the class of header to get it to work! Thanks all!


So I'm not sure "title" here means what you think it means. Setting the title on a view controller isn't going to affect what's in the view. If you're trying to set a title on a section, you may just want to use tableView:titleForHeaderInSection. tableView:viewForHeaderInSection is for more complex section headers (like if you wanted to put buttons, or multiple rows of text or something like that). If it matters, you can use both of these methods. I'm not 100% certain on the order they're called, but I'm pretty sure it looks for a viewForHeaderInSection and then if that's nil it goes to titleForHeaderInSection.


The function expects a UIView to be returned, but you appear to be returning a UIViewController. Did you mean to do return header.view?

0

精彩评论

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