我试图为我的tableview
. Tableview
本身工作正常,但由于某种原因,编译器跳过,
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
委托方法,我尝试了参考上写的内容,还有这个。我还tableView:heightForHeaderInSection:
按照参考页面中的建议添加了该方法,但由于某种原因,它只是不阅读这些方法。显然,我做错了什么。如果有人能指出我的错误,我将不胜感激。先感谢您。
profileViewController.h
#import <UIKit/UIKit.h>
#import "PeopleModel.h"
#import <QuartzCore/QuartzCore.h>
@interface profileViewController : UIViewController
<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic)NSMutableArray *People;
@property (weak, nonatomic) IBOutlet UITableView *profileTableView;
@end
profileViewController.m
#import "profileViewController.h"
@interface profileViewController ()
+ (UIImage *)scale:(UIImage *)image toSize:(CGSize)size;
@end
@implementation profileViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = @"ProfileView";
self.profileTableView.dataSource = self;
self.profileTableView.dataSource = self;
PeopleModel *person1 = [[PeopleModel alloc]init];
person1.Name =@"mett";
person1.Email= @"mett@gmail.com";
person1.ProfilePicture =[UIImage imageNamed:@"profileImage.jpg"];
self.People = [NSMutableArray arrayWithObjects:person1,person1, nil];
self.profileTableView.layer.cornerRadius = 8.0;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.People count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont systemFontOfSize:19.0];
cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
}
PeopleModel *item =[self.People objectAtIndex:indexPath.row];
cell.textLabel.text = item.Name;
cell.detailTextLabel.text = item.Email;
cell.imageView.image = item.ProfilePicture;
cell.imageView.image =[profileViewController scale:item.ProfilePicture toSize:CGSizeMake(115, 75)];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 15;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSLog(@"cartman!");
if (section == 0) {
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
UIView* headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, 44.0)];
//headerView.contentMode = UIViewContentModeScaleToFill;
// Add the label
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, -5.0, 300.0, 90.0)];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.text = @"section one";
headerLabel.textColor = [UIColor blueColor];
headerLabel.highlightedTextColor = [UIColor blackColor];
//this is what you asked
headerLabel.font = [UIFont boldSystemFontOfSize:17];
headerLabel.shadowColor = [UIColor clearColor];
headerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
headerLabel.numberOfLines = 0;
headerLabel.textAlignment = NSTextAlignmentCenter;
[headerView addSubview: headerLabel];
// Return the headerView
return headerView;
}
else return nil;
}
+ (UIImage *)scale:(UIImage *)image toSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end