在选择索引不正确的行时,我的 UITableView 顶部也出现空白行。它之前工作正常,但在我对 xcode 7 和 swift 2.0 进行更改后它不起作用。下面是我的代码。如果您有任何解决此问题的建议,请告诉我。
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()
}
}
}
最佳答案
var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath)
cell = UITableViewCell(style: UITableViewCellStyle.Subtitle,
reuseIdentifier: cellIdentifier)
这两行可能会造成一些混淆。您正在使一个单元格出列,而不是启动另一个单元格。
我认为,您应该只使用第一行来创建 tableView 单元格。并且该单元格应在 tableView 中正确设置为原型(prototype)单元格。
关于ios - 覆盖 swift 2.0 和 xcode 7 代码后 UITableView 中的空白行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33010477/