CustomCell.h
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell
{
UIImageView *imageView;
}
-(void)setTheImage:(UIImage *)icon;
@end
CustomCell.m
#import "CustomCell.h"
@implementation CustomCell
#pragma mark---------setTheImage------
-(void)setTheImage:(UIImage *)icon{
imageView = [[UIImageView alloc]initWithImage:icon];
imageView.frame = CGRectMake(0, 0, 320, 45);
[self.contentView addSubview:imageView];
}
#pragma mark ------去除cell的背景色
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self== [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//cell background kill
[self.contentView setBackgroundColor:[UIColor clearColor]];
}
return self;
}
#pragma mark ------调整cell选中与未选中的透明度
-(void)setSelected:(BOOL)selected animated:(BOOL)animated{
[super setSelected:selected animated:animated];
if (selected == YES) {
//
imageView.alpha =.5;
}else{
imageView.alpha =1;
}
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
CategoryViewController.h
#import <UIKit/UIKit.h>
@interface CategoryViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
{
UITableView *table;
NSMutableArray *muArr;
}
@end
CategoryViewController.m
#import "CategoryViewController.h"
#import "CustomCell.h"
@implementation CategoryViewController
#pragma mark -------UITableViewDelegate method(行高):
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 45;
}
#pragma mark ---点击某行触发的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// *nextViewController = [[<#NextViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// Configure the new view controller.
// [self.navigationController pushViewController:nextViewController animated:YES];
// [nextViewController release];
}
#pragma mark UITableViewDataSource method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
}
[cell setTheImage:[UIImage imageNamed:@"条纹.png"]];
//
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 300, 40)];
lbl.backgroundColor = [UIColor clearColor];
lbl.tag = indexPath.row;
lbl.textColor = [UIColor blackColor];
lbl.text = @"第一章:秦始皇统一六国概述";//arry indexPath.row
[cell addSubview:lbl];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 9;//array count
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;{
return 1;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:YES]; self.navigationController.navigationBar.hidden = YES;}// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.- (void)viewDidLoad{ [super viewDidLoad]; self.navigationController.navigationBar.hidden = YES; UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 436)]; imageView.image = [UIImage imageNamed:@"Default.png"]; [self.view addSubview:imageView]; [imageView release]; table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 436) style:UITableViewStylePlain]; table.scrollEnabled = YES; table.delegate = self; table.dataSource = self; table.backgroundColor = [UIColor clearColor]; table.separatorStyle = UITableViewCellSeparatorStyleNone;// 去掉cell的线 table.indicatorStyle = UIScrollViewIndicatorStyleWhite; [self.view addSubview:table]; }- (void)viewDidUnload{ [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil;}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait);}@end#pragma mark - 在viewWillAppear去掉navigationBar(顶部的导航)