0

I have a storyboard TableView with a Custom storyboard TableViewContoller class. I'd like to add an icon to the header of the TableView, but am having a hard time trying to figure out how to do it. I don't see the header in my TableViewController in the storyboard, and ran across a Stack post which said to just drag the UIImageView to the top of the prototype cells but this doesn't seem to work quite right.

result of code

I then got an IBOutlet hooked up to the storyboard UIImageView and populate that property from viewDidLoad in my TableViewController custom class:

@property (weak, nonatomic) IBOutlet UIImageView *mImagePic;
...
- (void)viewDidLoad
{
    UIImage *pic = _mPersonPhoto;
    [_mImagePic setImage:pic];
...
}

This sort of works, but the image ends up in the first tableview row and I want it in the Header so it doesn't disappear under the header when scrolling the list. So, then I tried this:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
   UIImage *pic = _personPhoto;
   [_mImagePic setImage:pic];
   return (_mImagePic);
}

The second code snip does about the same thing as the first, but the pic is still not in the header (screenshot above). It's made the first row higher, but that's about it. I guess the next try is to create the entire header from code in viewForHeaderInSection but that seems to make storyboarding pointless. How can I get the picture in the Header without having to rebuild the whole Header (adding back button, title, etc)?

4

2 回答 2

0

最终将 UIView 和 UIImage 添加到情节提要的最顶部栏。您不能只在其中添加图像而不首先将其放置在视图中,这是我试图做的。

树视图故事板

然后我将视图和图片连接到我的 .m 文件中的属性:

@interface ...
@property (weak, nonatomic) IBOutlet UIImageView *mImagePic;
@property (weak, nonatomic) IBOutlet UIView *mPicView;
@end

最后,在 viewDidLoad 中,我用我想要的图片加载了 mImagePic。

- (void)viewDidLoad
   {

       UIImage *pic = [picArray objectAtIndex:2];
       [_mImagePic setImage:pic];

       // make transparent View background
       // ! requires unchecking Opaque property in storyboard
       [_mPicView setBackgroundColor:[UIColor clearColor]];
       ...
    }
于 2013-10-03T17:17:36.857 回答
0

设置 tableHeaderView

tableHeaderView 返回显示在表格上方的附件视图。

@property(nonatomic, retain) UIView *tableHeaderView Discussion 默认值为 nil。表头视图不同于节头。

可用性 适用于 iOS 2.0 及更高版本。另见 @property sectionHeaderHeight 在 UITableView.h 中声明

于 2013-10-02T21:30:40.163 回答