Last active
June 3, 2016 04:58
-
-
Save pingzh/84c6017096a25dba2d23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyAccountViewController: UIViewController { | |
private var _leftBarButtion: UIBarButtonItem! | |
private var _rightBarButton: UIBarButtonItem! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
addSubviews() | |
addLayout() | |
} | |
func addSubviews() { | |
view.addSubview(userInfoView) | |
//nav button | |
navigationItem.title = "My Account" | |
navigationItem.leftBarButtonItem = leftBarButtion | |
navigationItem.rightBarButtonItem = rightBarButton | |
view.addSubview(line) | |
view.addSubview(tableView) | |
} | |
func addLayout() { | |
} | |
override func viewWillAppear(animated: Bool) { | |
super.viewWillAppear(animated) | |
initData() | |
} | |
func initData() { | |
setUserInfo() | |
loadMyAccountItems() | |
} | |
} | |
extension MyAccountViewController: UITableViewDataSource, UITableViewDelegate { | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return functions.count | |
} | |
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
let reuseId = "MyAccountTableViewCell" | |
let cell: MyAccountTableViewCell | |
if let reuseCell = tableView.dequeueReusableCellWithIdentifier(reuseId) as? MyAccountTableViewCell { | |
cell = reuseCell | |
} | |
else { | |
cell = MyAccountTableViewCell(style: .Subtitle, reuseIdentifier: reuseId) | |
} | |
let function = functions[indexPath.row] | |
cell.setMyAccountFunction(function) | |
return cell | |
} | |
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | |
let selectedTwitter = twitters[indexPath.row] | |
let twitterDetail = TwitterDetailViewController() | |
twitterDetail.selectedTwitter = selectedTwitter | |
self.navigationController?.pushViewController(twitterDetail, animated: true) | |
NSLog("didSelect") | |
} | |
} | |
extension MyAccountViewController { | |
func didPressLeftBarButtion() { | |
User.clearCurrentUser() | |
dismissViewControllerAnimated(true, completion: nil) | |
print("didPressSignOutButton") | |
} | |
func didPressRightBarButton() { | |
print("didPressNewTwitterButton") | |
let newTwitterPage = NewTwitterViewController() | |
newTwitterPage.username = "pzhang" | |
newTwitterPage.profileImageUrl = "http://pbs.twimg.com/profile_images/1296339574/foxnews-avatar_normal.png" | |
newTwitterPage.name = "Ping Zhang" | |
let newTwitterPageNav = TwitterNavigationViewController(rootViewController: newTwitterPage) | |
presentViewController(newTwitterPageNav, animated: true, completion: nil) | |
} | |
} | |
extension MyAccountViewController { | |
var leftBarButtion: UIBarButtonItem { | |
if _leftBarButtion == nil { | |
_leftBarButtion = UIBarButtonItem(title: "Sign Out", style: .Plain, target: self, action: "didPressLeftBarButtion") | |
} | |
return _leftBarButtion | |
} | |
var _rightBarButton: UIBarButtonItem { | |
if _rightBarButton == nil { | |
_rightBarButton = UIBarButtonItem(title: "New", style: .Plain, target: self, action: "didPressRightBarButton") | |
} | |
return _rightBarButton | |
} | |
var tableView: UITableView { | |
if _tableView == nil { | |
_tableView = UITableView() | |
_tableView.delegate = self | |
_tableView.dataSource = self | |
_tableView.estimatedRowHeight = 80 | |
_tableView.rowHeight = UITableViewAutomaticDimension | |
_tableView.backgroundColor = UIColor.clearColor() | |
_tableView.separatorColor = UIColor.blackColor() | |
_tableView.separatorInset = UIEdgeInsetsZero | |
_tableView.scrollEnabled = false | |
_tableView.tableFooterView = UIView(frame: CGRectZero) | |
} | |
return _tableView | |
} | |
var followingNumer: UIButton { | |
if _followingNumer == nil { | |
_followingNumer = UIButton() | |
_followingNumer.titleLabel?.lineBreakMode = .ByWordWrapping | |
_followingNumer.titleLabel?.textAlignment = .Left | |
_followingNumer.titleLabel?.font = TprofileButtonFont | |
_followingNumer.setTitleColor(TprofileButtonFontColor, forState: .Normal) | |
_followingNumer.setTitle("222\nFollowiing", forState: .Normal) | |
} | |
return _followingNumer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment