关于tableView的简单实例

时间:2023-03-10 07:41:48
关于tableView的简单实例

关于tableCell选中颜色

//无色

cell.selectionStyle = UITableViewCellSelectionStyleNone;

//蓝色
cell.selectionStyle = UITableViewCellSelectionStyleBlue;

//灰色
cell.selectionStyle = UITableViewCellSelectionStyleGray;

设置tableViewCell间的分割线的颜色

[theTableView setSeparatorColor:[UIColor xxxx ]];


自定义UITableViewCell选中时背景

cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellart.png"]] autorelease]; 
    还有字体颜色 
    cell.textLabel.highlightedTextColor = [UIColor xxxcolor];  [cell.textLabel setTextColor:color];//设置cell的字体的颜色

改变UITableViewCell选中时背景色:

cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame] autorelease];


   cell.selectedBackgroundView.backgroundColor = [UIColor xxxxxx];

我自己的一个实例:

#import "AndyViewController.h"

@interfaceAndyViewController ()

@end

@implementation AndyViewController

- (void)viewDidLoad

{

[superviewDidLoad];

NSArray *array=[[[NSArrayalloc] initWithObjects:@"monday",@"tunesday",@"thursday",@"firday",@"staturday",@"sunday",nil] autorelease];

self.listdata=array;

// Do any additional setup after loading the view, typically from a nib.

}

- (void)didReceiveMemoryWarning

{

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

-(void)dealloc

{

[super dealloc];

[_listdatarelease];

[_tableViewrelease];

}

#pragma UITableViewDataSourc delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return [self.listdata count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

staticNSString *identifier=@"SimpleTableIdentifier";

UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];

if(cell==nil)

{

cell=[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefault

reuseIdentifier:identifier];

}

cell.imageView.image=[UIImageimageNamed:@"star.png"];

cell.textLabel.textColor=[UIColorredColor];

cell.textLabel.text=[self.listdataobjectAtIndex:indexPath.row];

cell.selectionStyle=UITableViewCellSelectionStyleNone;

return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return 90;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

NSString *message=[self.listdata objectAtIndex:indexPath.row];

UIAlertView *alert=[[UIAlertViewalloc] initWithTitle:@"you have selected "message:message delegate:selfcancelButtonTitle:@"取消"otherButtonTitles: nil];

[alert show];

}

@end

相关文章