Swift Xcode 6推送segue表视图布局错误

时间:2015-01-09 20:02:44

标签: ios xcode swift storyboard segue

对于我的一个表视图,当我在该视图上激活push segue然后返回时,布局会混乱。表格视图从屏幕顶部显着移动。我正在使用故事板来处理所有约束和视图。附上图片(或imgur album:http://imgur.com/a/SZKc3#roDklmm):

Push push之前(右上方按钮) before segue

在segue期间 during segue

按下后 after pressing back

故事板和限制: storyboard constraints

我的控制器代码:

import UIKit

class NotificationViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, APINotificationProtocol {

@IBOutlet var tableView: UITableView!
var notifications = NSMutableArray()
var refresher = UIRefreshControl()
override func viewDidLoad() {
    super.viewDidLoad()
    api.delegateNotification = self
    api.getNotifications()
    tableView.reloadData()
    refresher.attributedTitle = NSAttributedString()
    refresher.addTarget(self, action: "refresh", forControlEvents: UIControlEvents.ValueChanged)
    self.tableView.addSubview(refresher)
}

func refresh() {
    api.getNotifications()
    self.refresher.endRefreshing()
}

func didReceiveNotificationResults(results: NSDictionary) {
    var newProducts = results.valueForKey("feed") as NSArray
    notifications = newProducts as NSMutableArray
    dispatch_async(dispatch_get_main_queue()) {
      self.tableView.reloadData()
    }
}

override func viewWillAppear(animated: Bool) {
   // api.getNotifications()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return notifications.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell: NotificationTableViewCell = tableView.dequeueReusableCellWithIdentifier("notificationCell") as NotificationTableViewCell
    var alert: NSDictionary = notifications[indexPath.row] as NSDictionary
    var user: NSDictionary = alert.valueForKey("user") as NSDictionary
    var type: String = alert.valueForKey("type") as String
    var name = user.valueForKey("name") as String
    cell.userImage.image = UIImage(named: "b&W")
    cell.userImage = gifyImageView(cell.userImage)

    var attributedName = NSMutableAttributedString(string: name)
    attributedName.addAttribute(NSForegroundColorAttributeName, value: UIColor(red: 120.0/255.0, green: 69.0/255.0, blue: 193.0/255.0, alpha: 1.0), range: NSRange(location:0,length:attributedName.length))
    var url = NSURL.URLWithString(user.valueForKey("avatar") as String)
    var request: NSURLRequest = NSURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.ReturnCacheDataElseLoad, timeoutInterval: 2.0)

    var urlConnection: NSURLConnection = NSURLConnection(request: request, delegate: self)
    NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in

        if error == nil {
            var image = UIImage(data: data)
            cell.userImage.image = image
        }
    })

    switch type {
        case "seen":
            var endString = NSMutableAttributedString(string: " saw your item")
            attributedName.appendAttributedString(endString)
            cell.alertLabel.attributedText = attributedName
            var product = alert.valueForKey("product") as NSDictionary
            var url = NSURL.URLWithString(product.valueForKey("image") as String)
            var request: NSURLRequest = NSURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.ReturnCacheDataElseLoad, timeoutInterval: 2.0)

            var urlConnection: NSURLConnection = NSURLConnection(request: request, delegate: self)
            NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in

                if error == nil {
                    var image = UIImage(data: data)
                    cell.productImage.image = image
                }
            })
        case "shared":
            var endString = NSMutableAttributedString(string: " shared your item")
            attributedName.appendAttributedString(endString)
            cell.alertLabel.attributedText = attributedName
            var product = alert.valueForKey("product") as NSDictionary
            var url = NSURL.URLWithString(product.valueForKey("image") as String)
            var request: NSURLRequest = NSURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.ReturnCacheDataElseLoad, timeoutInterval: 2.0)

            var urlConnection: NSURLConnection = NSURLConnection(request: request, delegate: self)
            NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in

                if error == nil {
                    var image = UIImage(data: data)
                    cell.productImage.image = image
                }
            })
        case "follow":
            var endString = NSMutableAttributedString(string: " is now following you")
            attributedName.appendAttributedString(endString)
            cell.alertLabel.attributedText = attributedName
        default:
          println("default")
    }

    cell.dateLabel.text = alert.valueForKey("date") as? String

    return cell
}

}

任何人都知道发生了什么事吗?谢谢你的帮助。

0 个答案:

没有答案