我在UITableView的頂部獲得了空白行,並且選擇了索引不正確的行。它之前工作正常,但它沒有工作後,我改變了Xcode 7和Swift 2.0。以下是我的代碼。如果您有任何解決此問題的建議,請告訴我。UITableView中的空行在轉換swift 2.0和xcode 7的代碼之後
class DistributionAPNTableViewController: UITableViewController, UIPopoverPresentationControllerDelegate,UpdateUIDelegate {
var jsonReleaseNotificationArray:NSArray = []
var activityView : UIActivityIndicatorView = UIActivityIndicatorView()
override func viewDidLoad() {
super.viewDidLoad()
let url: String = Constants.RelNotificationsURL
let restCall = CallRESTParser()
restCall.uiDelegate=self
self.showProgress()
restCall.processRequest(url,type: Constants.RelNotificationsType)
}
func UpdateReleaseNotificationUI(jsonArray:NSArray){
self.dismissProgress()
jsonReleaseNotificationArray = jsonArray
self.tableView.reloadData()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var cnt:Int = 0
if jsonReleaseNotificationArray.count > 0 {
cnt = jsonReleaseNotificationArray.count
}
else if jsonReleaseNotificationArray.count == 0{
cnt = 1
}
return cnt
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "RelCell"
var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath)
cell = UITableViewCell(style: UITableViewCellStyle.Subtitle,
reuseIdentifier: cellIdentifier)
if jsonReleaseNotificationArray.count > 0{
let jsonResult = jsonReleaseNotificationArray[indexPath.row] as? NSDictionary
if let noti = jsonResult!.objectForKey("notification") as? String{
cell.textLabel?.text = noti
cell.textLabel?.font = UIFont(name:"Avenir", size:14)
}
if let user = jsonResult!.objectForKey("userid") as? String{
cell.detailTextLabel?.text = "Updated By : \(user)"
}
}else
{
cell.textLabel?.text = "There is no release notifications yet."
cell.textLabel?.font = UIFont(name:"Avenir", size:14)
}
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let jsonResult = jsonReleaseNotificationArray[indexPath.row] as? NSDictionary
let destination:NotificationDetails = storyboard!.instantiateViewControllerWithIdentifier("notification") as! NotificationDetails
if let noti = jsonResult!.objectForKey("notification") as? String{
destination.messageStr = noti
}
if let user = jsonResult!.objectForKey("userid") as? String{
destination.updatedByStr = user
}
navigationController?.pushViewController(destination, animated: true)
}
func UpdateProjectUI(data:NSDictionary){
}
@available(iOS 8.0, *)
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle
{
return UIModalPresentationStyle.None
}
func showProgress() {
self.view.alpha = 0.5
self.view.userInteractionEnabled = false
self.activityView.center = self.view.center
self.activityView.color = UIColor.blackColor()
self.view .addSubview(self.activityView)
self.activityView.startAnimating()
}
func dismissProgress() {
self.activityView.stopAnimating()
self.activityView.removeFromSuperview()
self.view.alpha = 1.0
self.view.userInteractionEnabled = true
}
func UpdateRelNotiByMsgUI(data:NSDictionary){
}
func ErrorHasOccured(error:String){
self.dismissProgress()
if #available(iOS 8.0, *) {
let alert = UIAlertController(title: "IBM Vidur", message: error, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
} else {
let alertController: UIAlertView = UIAlertView(title: "IBM Vidur", message:error, delegate: nil, cancelButtonTitle: "OK")
alertController.show()
}
}
}
好的,我們如何設置它在單行?我也需要字幕。 – RichieRich
在故事板中設計您的tableViewCell,以獲得所需的標籤。 – dirtydanee