表视图导航栏正在关闭

时间:2017-06-02 11:20:07

标签: ios swift xcode swift3 storyboard

我尝试在Main.storyboard中向表视图添加导航栏。 在Main.storyboard中,在表视图的向上部分中看到导航栏没有问题。

此外,在加载数据之前没问题。导航栏位于表格视图的向上部分。

Image 1

但是,当加载所有数据时,导航栏将向下

Image 2

我想在tableview的上方保留导航栏。 我哪里错了?如何解决这个问题呢?

我认为,FirstViewController.swift并不重要,但我正在共享所有代码。

FirstViewController.swift

Tag

3 个答案:

答案 0 :(得分:1)

Try this

这将创建一个导航栏

答案 1 :(得分:1)

问题是您已将NavigationBarObject library拖放到ViewController,因此请将其删除。如果您想将NavigationBar嵌入YourViewController显示为UINavigtionController

Embed ViewController NavigationConttoller,请执行以下步骤。

  1. 在“界面构建器”
  2. 中选择ViewController
  3. 转到Editor菜单,然后选择嵌入。
  4. 从新选项列表中选择NavigationController
  5. 要将title设置为Navigation bar,请在Navigation Item之后从Document Outline Bar部分选择Attribute Inspector的View viewDidLoad并设置标题。< / p>

    您还可以通过编程方式设置标题,在self.title = "Title"

    中添加以下行
    location_thread = new Thread() {
    
                @Override
                public void run() {
                    try {
                        while (!isInterrupted()) {
                            Thread.sleep(2000);
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Log.i("TAG",currentThread().getName()+" Running");
                                    updateLatLongInfo();
                                }
                            });
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            location_thread.setDaemon(false);
            location_thread.start();
        }
    
        @Override
    //whenever user press a backbutton thread must stoppped
        public void onBackPressed() {
            super.onBackPressed();
            location_thread.stop();
            Intent intent = new Intent(Logistic_ReportProblem.this, FPAgentHome.class);
            startActivity(intent);
            finish();
        }
    
    
        private void updateLatLongInfo() {
            try {
                int locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
                latlongInfo.setBackgroundResource(R.drawable.latlng_info);
                GradientDrawable drawable = (GradientDrawable) latlongInfo.getBackground();
                if (locationMode == 0 || locationMode == 1 || locationMode == 2) {
                    latlongInfo.setText("Please enable high accuracy in your location settings");
                    drawable.setColor(Color.RED);
                } else {
                    try {
                        String context = Context.LOCATION_SERVICE;
                        locationManager = (LocationManager) this.getSystemService(context);
                        String provider = LocationManager.GPS_PROVIDER;
                        android.location.Location location = locationManager.getLastKnownLocation(provider);
                        updateWithNewLocation(location);
                        locationManager.requestLocationUpdates(provider, 0, 0, locationListener);
    
                        param_latitude = df.format(lat).toString();
                        param_longitude = df.format(lng).toString();
    
                        // latlongInfo.setText("Latitude :" + Math.round(lat * 1000000.0) / 1000000.0 + " ," + " Longitude :" + Math.round(lng * 1000000.0) / 1000000.0);
                        latlongInfo.setText("Latitude : " + param_latitude + " ," + " Longitude : " + param_longitude);
                        latlongInfo.setGravity(Gravity.CENTER);
                        drawable.setColor(Color.GREEN);
                    } catch (SecurityException e) {
                        Log.e("Error", e.toString());
                    }
                }
    

    enter image description here

答案 2 :(得分:0)

按照我的视图尝试在tableview的标题视图中设置导航栏。不会向下移动。