在不触及屏幕的情况下无法查看表格视图项目

时间:2016-01-28 05:28:24

标签: ios arrays uitableview uitabbarcontroller nsmutableurlrequest

我的tableView类中存在一些问题我从我的服务器获取数据并且可以在表中查看但问题是当我从服务器完全获取数据时它从未在表视图中显示,直到我触及屏幕..当我触摸屏幕时,我可以看到我的数据,但是当我得到数据时,我想查看我的数据..这是我的班级 ..

import Foundation
import UIKit

class MovementRep : UIViewController , UITableViewDelegate, UITableViewDataSource{


var unitID : Int = 0;
var count : Int = 0;

var dateTime = [String]()
var speed = [Double]()
var event = [String]()
var location = [String]()

var len : Int = 0;

var deviation = [String]()


@IBOutlet weak var ActivityIndicator: UIActivityIndicatorView!


@IBOutlet weak var tableView: UITableView!


override func viewDidLoad() {
    super.viewDidLoad()
    print("Movement Report Called");
    print("unit ID = \(unitID)")

    var id : String = String(self.unitID);
    print("string id = \(id)")


    //Send Server Request

    let myURL = NSURL(string: "<URL>");
    let request = NSMutableURLRequest(URL: myURL!);
    request.HTTPMethod = "POST";





    let task = NSURLSession.sharedSession().dataTaskWithRequest(request){
        data, responce, error in


        self.ActivityIndicator.startAnimating()

        if error != nil{
            print("Error = \(error)")

        }

      //  print("Responce = \(responce)")



        //    let responceString = NSString(data:data,encodeing:NSTUF8StringEncoding);
        //   print("Responce Data = \(responceString)");


        do {
            if let jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary {

             //   print("JSONResult = \(jsonResult)")

                let size = jsonResult["size"] as? Int
                print("result: \(size)");

                self.len = size!;

                if let Users = jsonResult["movementReport"] as? [[String: AnyObject]] {


                    //when you got irrespective response of numberOfRowsInSe...

                    //http://stackoverflow.com/questions/31498531/numberofrowsinsection-is-called-before-alamofire-connection/31498570#31498570

                    self.tableView.reloadData()


                    for name in Users {



                        //if you got null from Json ...
                        if let msg = name["message"] as? NSNull{
                            //print("got \(d)")
                            self.location.append("null")
                        }

                        //simple chk
                        if let message = name["message"] as? String
                        {

                            self.location.append(message)


                        }

                        //if you got null from Json ...
                        if let dt = name["dateTime"] as? NSNull{
                            //print("got \(d)")
                            self.location.append("null")
                        }

                        //simple chk
                        if let date = name["dateTime"] as? String
                        {

                            self.dateTime.append(date)


                        }

                        //if you got null from Json ...
                        if let sp = name["speed"] as? NSNull{
                            //print("got \(d)")
                            self.speed.append(0.0)
                        }

                        //simple chk
                        if let speed = name["speed"] as? Double
                        {

                            self.speed.append(speed)


                        }




                        //if you got null from Json ...
                        if let ev = name["reportText"] as? NSNull{
                            //print("got \(d)")
                            self.event.append("null")
                        }

                        //simple chk
                        if let event = name["reportText"] as? String

                        {

                            self.event.append(event)


                        }

                        //if you got null from Json ...
                        if let dev = name["route"] as? NSNull{
                            //print("got \(d)")
                            self.deviation.append("--")
                        }

                        //simple chk
                        if let devtion = name["route"] as? String

                        {

                            self.deviation.append(devtion)

                        }

                    }

                }


            }
        } catch let error as NSError {
            print(error.localizedDescription)
        }
    }




    task.resume();

    self.tableView.reloadData();


}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    print("ViewWillAppearCaled")

   self.tableView.reloadData();
}

override func viewDidAppear(animated: Bool) {
    super.viewWillAppear(animated)
    print("ViewDidAppearCaled")
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    print("table view row")
    return len
}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    print("table view cell")

    let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell

    if (len > 0){

    cell.date.text = dateTime[indexPath.row];
    cell.speed.text = "\(speed[indexPath.row])"
    cell.position.text = event[indexPath.row]
    cell.location.text = location[indexPath.row]
    cell.deviation.text = deviation[indexPath.row]
         cell.index.text = "\(indexPath.row+1)";
         self.ActivityIndicator.stopAnimating()

         return cell

    }

    return cell
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 200.0
}

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

    cell.contentView.backgroundColor = UIColor.clearColor()

    let whiteRoundedView : UIView = UIView(frame: CGRectMake(6, 6, self.view.frame.size.width, 200.0))

    whiteRoundedView.layer.backgroundColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), [1.8, 1.8, 1.8, 1.8])
    whiteRoundedView.layer.masksToBounds = false
    whiteRoundedView.layer.cornerRadius = 3.0
    //whiteRoundedView.layer.shadowOffset = CGSizeMake(-1, 1)
        whiteRoundedView.layer.shadowOpacity = 0.1

        cell.contentView.addSubview(whiteRoundedView)
        cell.contentView.sendSubviewToBack(whiteRoundedView)
    }


}

1 个答案:

答案 0 :(得分:0)

尝试替换此代码:

 <html>
    <head>
        <title>sample Page</title>
    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>

    <script>

        $(document).ready(function () {


            $('button').click(function () {
                var Outcome;

                Outcome = $('input[name="Outcome"]:checked').val();


                if (Outcome == "Done") {
                    alert('condition1')
                }
                else if (Outcome == "NotClean") {

                    alert('condition2')
                    }

            })

        });


    </script>
    </head>
    <body>
        <button >check Condition</button>
       <input type="radio" name="Outcome" value="Done" >Done<br/>
<input type="radio" name="Outcome" value="NotClean">NotClean<br/>
    </body>
    </html>