Skip to content

Commit

Permalink
修复一些变量作用域问题
Browse files Browse the repository at this point in the history
  • Loading branch information
15038777234 committed Mar 16, 2017
1 parent 52d57be commit 7ceb863
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -94,4 +94,4 @@ pod 'ZHTableViewGroupSwift'

```swift
self.dataSource?.clearData()
```
```
23 changes: 3 additions & 20 deletions ZHTableViewGroupSwift.podspec
Expand Up @@ -9,33 +9,16 @@
Pod::Spec.new do |s|
s.name = 'ZHTableViewGroupSwift'
s.version = '0.1.0'
s.summary = 'A short description of ZHTableViewGroupSwift.'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!

s.description = <<-DESC
TODO: Add long description of the pod here.
DESC

s.homepage = 'https://github.com/15038777234/ZHTableViewGroupSwift'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.summary = 'ZHTableViewGroup为 UITableView 而生'
s.homepage = 'https://github.com/josercc/ZHTableViewGroupSwift'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { '15038777234' => '15038777234@163.com' }
s.source = { :git => 'https://github.com/15038777234/ZHTableViewGroupSwift.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

s.source = { :git => 'https://github.com/josercc/ZHTableViewGroupSwift.git', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'

s.source_files = 'ZHTableViewGroupSwift/Classes/**/*'

# s.resource_bundles = {
# 'ZHTableViewGroupSwift' => ['ZHTableViewGroupSwift/Assets/*.png']
# }

# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
Expand Down
4 changes: 2 additions & 2 deletions ZHTableViewGroupSwift/Classes/ZHTableViewCell.swift
Expand Up @@ -18,9 +18,9 @@ public class ZHTableViewCell: NSObject {

public var cellNumber:Int = 0

var configCompletionHandle:ZHTableViewCellCompletionHandle?
private var configCompletionHandle:ZHTableViewCellCompletionHandle?

var didSelectRowCompletionHandle:ZHTableViewCellCompletionHandle?
private var didSelectRowCompletionHandle:ZHTableViewCellCompletionHandle?

public var anyClass:AnyClass?

Expand Down
16 changes: 8 additions & 8 deletions ZHTableViewGroupSwift/Classes/ZHTableViewDataSource.swift
Expand Up @@ -24,7 +24,7 @@ public class ZHTableViewDataSource: NSObject {
}

/// ZHTableViewGroup的数组
public var groups:[ZHTableViewGroup] = []
private var groups:[ZHTableViewGroup] = []

/// 初始化ZHTableViewDataSource数据源
///
Expand All @@ -35,14 +35,14 @@ public class ZHTableViewDataSource: NSObject {
}

/// 托管 UITableView 的对象
var tableView:UITableView
private var tableView:UITableView

public func reloadTableViewData() {
self.registerClass()
self.tableView.reloadData()
}

func registerClass() {
private func registerClass() {
for group in self.groups {
group.registerHeaderFooterCell(tableView: self.tableView)
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public class ZHTableViewDataSource: NSObject {
/// - dataSource: ZHTableViewDataSource的数据源可以为 nil
/// - section: 分组的索引
/// - Returns: 对应分组对象可能为 nil
class func groupForSection(dataSource:ZHTableViewDataSource?, section:Int) -> ZHTableViewGroup? {
private class func groupForSection(dataSource:ZHTableViewDataSource?, section:Int) -> ZHTableViewGroup? {
guard let dataSource = dataSource else {
// 当用户还没有创建ZHTableViewDataSource对象返回 nil
return nil
Expand All @@ -98,7 +98,7 @@ public class ZHTableViewDataSource: NSObject {
return dataSource.groups[section]
}

class func cellForIndexPath(dataSource:ZHTableViewDataSource?, atIndexPath indexPath:IndexPath) -> ZHTableViewCell? {
private class func cellForIndexPath(dataSource:ZHTableViewDataSource?, atIndexPath indexPath:IndexPath) -> ZHTableViewCell? {
guard let group = groupForSection(dataSource: dataSource, section: indexPath.section) else {
return nil
}
Expand All @@ -124,7 +124,7 @@ public class ZHTableViewDataSource: NSObject {
return heightWithCustomHandle(height: cell.height, customCompletionHandle: customHeightCompletionHandle)
}

class func heightWithCustomHandle(height:CGFloat, customCompletionHandle:ZHTableViewDataSourceCustomHeightCompletionHandle?) -> CGFloat {
private class func heightWithCustomHandle(height:CGFloat, customCompletionHandle:ZHTableViewDataSourceCustomHeightCompletionHandle?) -> CGFloat {
if height == CGFloat(NSNotFound) {
guard let customCompletionHandle = customCompletionHandle else {
return 0
Expand All @@ -151,7 +151,7 @@ public class ZHTableViewDataSource: NSObject {
return heightForHeaderFooterInSection(dataSource: dataSource, section: section, customHeightCompletionHandle: customHeightCompletionHandle, headerFooterStyle: .footer)
}

class func heightForHeaderFooterInSection(dataSource:ZHTableViewDataSource?, section:Int, customHeightCompletionHandle:ZHTableViewDataSourceCustomHeightCompletionHandle?, headerFooterStyle:ZHTableViewHeaderFooterStyle) -> CGFloat {
private class func heightForHeaderFooterInSection(dataSource:ZHTableViewDataSource?, section:Int, customHeightCompletionHandle:ZHTableViewDataSourceCustomHeightCompletionHandle?, headerFooterStyle:ZHTableViewHeaderFooterStyle) -> CGFloat {
guard let group = groupForSection(dataSource: dataSource, section: section) else {
return 0
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public class ZHTableViewDataSource: NSObject {
return viewHeaderFooterInSection(dataSource: dataSource, section: section, style: .footer)
}

class func viewHeaderFooterInSection(dataSource:ZHTableViewDataSource?, section:Int, style:ZHTableViewHeaderFooterStyle) -> UITableViewHeaderFooterView? {
private class func viewHeaderFooterInSection(dataSource:ZHTableViewDataSource?, section:Int, style:ZHTableViewHeaderFooterStyle) -> UITableViewHeaderFooterView? {
guard let group = groupForSection(dataSource: dataSource, section: section) else {
return nil
}
Expand Down
17 changes: 9 additions & 8 deletions ZHTableViewGroupSwift/Classes/ZHTableViewGroup.swift
Expand Up @@ -12,13 +12,14 @@ public typealias ZHTableViewGroupAddCellCompletionHandle = (_ cell:ZHTableViewCe
public typealias ZHTableViewGroupAddHeaderFooterCompletionHandle = (_ headerFooter:ZHTableViewHeaderFooter) -> Void

public class ZHTableViewGroup: NSObject {
public var cells:[ZHTableViewCell] = []

var header:ZHTableViewHeaderFooter?
var cells:[ZHTableViewCell] = []

var footer:ZHTableViewHeaderFooter?
public var header:ZHTableViewHeaderFooter?

public var cellCount:Int {
public var footer:ZHTableViewHeaderFooter?

var cellCount:Int {
get {
var count:Int = 0
for cell in self.cells {
Expand Down Expand Up @@ -53,7 +54,7 @@ public class ZHTableViewGroup: NSObject {
/// - tableView: 对应的表格 可能为 nil
/// - indexPath: 对应的 IndexPath 索引
/// - Returns: UITableViewCell可能为 nil
public func cellForTableView(tableView:UITableView?, atIndexPath indexPath:IndexPath) -> UITableViewCell? {
func cellForTableView(tableView:UITableView?, atIndexPath indexPath:IndexPath) -> UITableViewCell? {
guard let tableView = tableView else {
// 当表格不存在返回 nil
return nil
Expand All @@ -71,7 +72,7 @@ public class ZHTableViewGroup: NSObject {
return cell
}

public func headerFooterForStyle(tableView:UITableView?, style:ZHTableViewHeaderFooterStyle) -> UITableViewHeaderFooterView? {
func headerFooterForStyle(tableView:UITableView?, style:ZHTableViewHeaderFooterStyle) -> UITableViewHeaderFooterView? {
guard let tableView = tableView else {
return nil
}
Expand All @@ -93,7 +94,7 @@ public class ZHTableViewGroup: NSObject {
return tableView.dequeueReusableHeaderFooterView(withIdentifier: identifier)
}

public func registerHeaderFooterCell(tableView:UITableView) {
func registerHeaderFooterCell(tableView:UITableView) {
if let headerIdentifier = self.header?.identifier {
tableView.register(self.header?.anyClass, forHeaderFooterViewReuseIdentifier: headerIdentifier)
}
Expand All @@ -113,7 +114,7 @@ public class ZHTableViewGroup: NSObject {
///
/// - Parameter indexPath: IndexPath 的索引
/// - Returns: ZHTableViewCell可能为 nil
public func tableViewCellForIndexPath(indexPath:IndexPath) -> ZHTableViewCell? {
func tableViewCellForIndexPath(indexPath:IndexPath) -> ZHTableViewCell? {
guard indexPath.row < self.cellCount else {
// 如果索引超出了总个数就返回 nil
return nil
Expand Down

0 comments on commit 7ceb863

Please sign in to comment.