UITableView+UISwitch实现对新闻显示的设置

本文介绍如何在iOS应用中通过UITableView和UISwitch实现新闻显示的个性化设置,包括显示图片、作者、日期等选项,并将用户设置保存到plist文件。在编程过程中需要注意避免UITableView的加载歧义,以及在代码中养成良好的编程习惯。同时,文章讨论了如何通过Category扩展UISwitch以提升用户体验,但遇到在新SDK中可能导致应用卡死的问题。
摘要由CSDN通过智能技术生成

     新闻显示页面的设置,主要实现以下功能:

     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文件:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值