UITableView常用属性和方法(一)

2014-11-24 02:02:50 · 作者: · 浏览: 4
常用属性:
第一、分割线的颜色和style:
@property(nonatomic)UITableViewCellSeparatorStyle separatorStyle; // default is UITableViewCellSeparatorStyleSingleLine
@property(nonatomic,retain)UIColor *separatorColor; // default is the standard separator gray
代码:
[cpp]
self.tableView.separatorColor=[UIColor yellowColor];
self.tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLineEtched;
[self.view addSubview:self.tableView];
第二、设置背景颜色
[cpp]
self.tableView.backgroundColor=[UIColor blueColor];
UIImageView *imageView=[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"10179888.jpg"]]autorelease];
self.tableView.backgroundView=imageView;
第三 、设置headerView和footerView
@property(nonatomic,retain)UIView *tableHeaderView; // accessory view for above row content. default is nil. not to be confused with section header
@property(nonatomic,retain)UIView *tableFooterView;
[cpp]
UIView *topheadView=[[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)] autorelease];
topheadView.backgroundColor=[UIColor yellowColor];
self.tableView.tableHeaderView=topheadView;
UIView *topFootView=[[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)] autorelease];
topFootView.backgroundColor=[UIColor redColor];
self.tableView.tableFooterView=topFootView;
第四、触摸相关
@property(nonatomic,getter=isEditing)BOOL editing; // default is NO. setting is not animated.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
@property(nonatomic)BOOL allowsSelectionNS_AVAILABLE_ IOS(3_0); // default is YES. Controls whether rows can be selected when not in editing mode
第五、多点触摸相关
@property(nonatomic)BOOL allowsSelectionDuringEditing; // default is NO. Controls whether rows can be selected when in editing mode
@property(nonatomic)BOOL allowsMultipleSelectionNS_AVAILABLE_IOS(5_0); // default is NO. Controls whether multiple rows can be selected simultaneously
@property(nonatomic)BOOL allowsMultipleSelectionDuringEditingNS_AVAILABLE_IOS(5_0); // default is NO. Controls whether multiple rows can be selected simultaneously in editing mode
第六、跟cell 相关
- (NSInteger)numberOfSections;
- (NSInteger)numberOfRowsInSection:(NSInteger)section;
常用方法:
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animationNS_AVAILABLE_IOS(3_0);
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSectionNS_AVAILABLE_IOS(5_0);
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAni