func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let logined = true
var vc: UIViewController?
if !logined {
vc = storyboard.instantiateViewControllerWithIdentifier("loginVC")
} else {
vc = storyboard.instantiateInitialViewController()
}
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = vc
window?.makeKeyAndVisible()
return true
}
let dateFormatter = NSDateFormatter()
dateFormatter.timeStyle = NSDateFormatterStyle.NoStyle
let gmtTimeZone = NSTimeZone(abbreviation: "GMT")
dateFormatter.timeZone = gmtTimeZone
dateFormatter.dateFormat = "yyyyMMdd"
var dates = [String]()
let threeMonthAgoComponent = NSDateComponents()
threeMonthAgoComponent.month = -3
var date = NSDate()
let calendar = NSCalendar.currentCalendar()
let lastDate = calendar.dateByAddingComponents(threeMonthAgoComponent, toDate: date, options: NSCalendarOptions(rawValue: 0))
let dayAgoComponent = NSDateComponents()
dayAgoComponent.day = -1
while (date != lastDate) {
date = calendar.dateByAddingComponents(dayAgoComponent, toDate: date, options: NSCalendarOptions.MatchFirst)!
dates.append(dateFormatter.stringFromDate(date))
}
print(dates)
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
print(touch.view)
}
}
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
let lastRow = indexPath.row
if lastRow == objects.count - 1 {
fetchData(lastRow)
}
}
private func fetchData(lastRow: Int) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * Int64(NSEC_PER_SEC)), dispatch_get_main_queue()) { () -> Void in
let object = "New data"
self.objects.append(object)
self.tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: lastRow + 1, inSection: 0)], withRowAnimation: .Automatic)
}
}
// DetailViewController.h
@interface DetailViewController
...
@property(nonatomic, weak) NSString *addressString;
...
@end
// TableViewController.h
DetailViewController * detailViewController = [DetailViewController alloc] init];
detailViewController.addressString = array[index];
[self.navigationController pushViewController: detailViewController animated:YES];