@interface TableListViewController : UITableViewController
@implementation TableListViewController
//表格可以以分段或者以单个列表的形式显示其数据。对于简单的表格,返回1,表示整个表格应该作为一个列表显示。在分段列表中,返回2及以上的值。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
{
return 1;
}
//第二个调用,此方法返回每个分段的行数,处理简单列表时,返回整个表格的行数。
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"[UIFont familyNames].count,%d",[UIFont familyNames].count);
return [UIFont familyNames].count;
}
//第三个调用,返回某一个item
- (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cellForRowAtIndexPath ,%@",indexPath);
UITableViewCellStyle style = UITableViewCellStyleDefault;
UITableViewCell *cell = [tView dequeueReusableCellWithIdentifier:@"BaseCell"];
if (!cell)
cell = [[[UITableViewCell alloc] initWithStyle:style reuseIdentifier:@"BaseCell"] autorelease];
cell.textLabel.text = [[UIFont familyNames] objectAtIndex:indexPath.row];
return cell;
}
//选中某一列的时候调用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didSelectRowAtIndexPath ,%@",indexPath);
NSString *font = [[UIFont familyNames] objectAtIndex:indexPath.row];
[MAINLABEL setText:font];
[MAINLABEL setFont:[UIFont fontWithName:font size:18.0f]];
}
//第一个调用
- (void) loadView
{
NSLog(@"试图控制器,loadview加载");
[super loadView];
self.navigationItem.titleView = [[[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 200.0f, 30.0f)] autorelease];
[MAINLABEL setBackgroundColor:[UIColor clearColor]];
[MAINLABEL setTextColor:[UIColor whiteColor]];
[MAINLABEL setTextAlignment:UITextAlignmentCenter];
}
//UIScrollViewDelegate 中的方法,滚动调用
- (void) scrollViewDidScroll: (UIScrollView *) sv
{
NSLog(@"scrollViewDidScroll调用");
float percent = sv.contentOffset.y / sv.contentSize.height;
percent = 0.25 + 3 * (MAX(MIN(1.0f, percent), 0.0f) / 4.0f);
self.tableView.backgroundColor = [UIColor colorWithRed:percent * 0.20392 green:percent * 0.19607 blue:percent * 0.61176 alpha: 1.0f];
}
TableListViewController *tlvc = [[TableListViewController alloc] init];
//设置tabview的整体布局背景
tlvc.tableView.backgroundColor = COOKBOOK_PURPLE_COLOR;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:tlvc];
//设置UINavigationController的navigationBar背景颜色
nav.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;
来源:oschina
链接:https://my.oschina.net/u/936286/blog/120953