import UIKit
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
//新闻列表
@IBOutlet weak var newsTableView: UITableView!
//新闻数组集合
var dataArray:[HanggeArticle] = [HanggeArticle]()
//拉刷新控制器
var refreshControl = UIRefreshControl()
override func viewDidLoad() {
super.viewDidLoad()
self.automaticallyAdjustsScrollViewInsets = false
//添加刷新
refreshControl.addTarget(self, action: "refreshData",
forControlEvents: UIControlEvents.ValueChanged)
refreshControl.attributedTitle = NSAttributedString(string: "下拉刷新数据")
newsTableView.addSubview(refreshControl)
refreshData()
}
// 刷新数据
func refreshData() {
//移除老数据
self.dataArray.removeAll()
//随机添加条新数据(时间是当前时间)
for _ in ..< {
let atricle = HanggeArticle(title: "新闻标题\(Int(arcrandom()%))",
createDate: NSDate())
self.dataArray.append(atricle)
}
self.newsTableView.reloadData()
self.refreshControl.endRefreshing()
}
// 返回记录数
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataArray.count;
}
// 返回单元格内容
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle,
reuseIdentifier: "myCell")
//设置单元格标题
let atricle: HanggeArticle = dataArray[indexPath.row] as HanggeArticle
cell.textLabel?.text = atricle.title
//设置单元格副标题
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let str = dateFormatter.stringFromDate(atricle.createDate)
cell.detailTextLabel?.text = str
return cell;
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
//新闻结构体
struct HanggeArticle {
var title:String
var createDate:NSDate
}
2012-06-15 14:34:34.908 DevDivUIRefreshControl[722:10103] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIRefreshControl may only be managed by a UITableViewController' *** First throw call stack: (0x186fd72 0x1066e51 0x186fb4b 0x55a559 0x57238 0x5d482 0x55ad2 0x2ebb 0xeb2a3 0xeb30e 0x10b7e9 0x10b624 0x109aef 0x10999c 0x107adc 0x1082c6 0xecf24 0xed1e0 0xee084 0x5645c 0x5cf31 0x55ad2 0x4131d 0x414f6 0x4168c 0x49871 0x10a90 0x1196a 0x222be 0x22f9f 0x153fd 0x17ccf39 0x17ccc10 0x17e5da5 0x17e5b12 0x1816b46 0x1815ed4 0x1815dab 0x1128f 0x12e71 0x29fd 0x2925) libc++abi.dylib: terminate called throwing an exception (lldb)
self.refreshControl = [[UIRefreshControl alloc]init]; // self.refreshControl.tintColor = [UIColor blueColor]; self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"]; [self.refreshControl addTarget:self action:@selector(RefreshViewControlEventValueChanged) forControlEvents:UIControlEventValueChanged];
- (void) handleData
{
NSLog(@"refreshed");
[self.refreshControl endRefreshing];
self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
self.count++;
[self.tableView reloadData];
}
// // UIRefreshControl.h // UIKit // // Copyright 2012 Apple Inc. All rights reserved. // #import <Foundation/Foundation.h> #import <UIKit/UIControl.h> #import <UIKit/UIKitDefines.h> NS_CLASS_AVAILABLE_IOS(6_0) @interface UIRefreshControl : UIControl /* The designated initializer * This initializes a UIRefreshControl with a default height and width. * Once assigned to a UITableViewController, the frame of the control is managed automatically. * When a user has pulled-to-refresh, the UIRefreshControl fires its UIControlEventValueChanged event. */ - (id)init; @property (nonatomic, readonly, getter=isRefreshing) BOOL refreshing; @property (nonatomic, retain) UIColor *tintColor UI_APPEARANCE_SELECTOR; @property (n
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有