新闻显示页面的设置,主要实现以下功能:
1.一个UITableView页作为总的设置页,点击新闻显示,进入新闻详情设置页面,详情页面包含以下设置:是否显示图片,是否显示作者,是否显示日期,是否显示简介,调整图片位置(左或右)。
2.用户的设置被保存到plist文件,每次都先从plist配置文件中读取。
3.只有在用户选择了显示图片时才可对图片位置进行设定,否则“图片设置”开关被隐藏。
直接上代码,第一个.h文件:
#import <UIKit/UIKit.h>
#import "detailSettingViewController.h"//注意一定在头文件添加要跳转到的页面
@interface settingViewController : UITableViewController
{
}//这里并不需要添加UITableViewDelegate和UITableViewDataSource,因为本身就继承自UITableView。
@property(nonatomic,retain)IBOutlet UITableView *settingTableView;
@end
第一个.m文件
#import "settingViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface settingViewController ()
@end
@implementation settingViewController
@synthesize settingTableView=_settingTableView;
- (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 (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.imageView.layer.cornerRadius=12.0;
cell.imageView.layer.masksToBounds=YES;
cell.imageView.image=[UIImage imageNamed:@"Icon.png"];
cell.textLabel.text=@"新闻显示";
return cell;
}@end
第二个.h文件: