我尝试在Main.storyboard中向表视图添加导航栏。 在Main.storyboard中,在表视图的向上部分中看到导航栏没有问题。
此外,在加载数据之前没问题。导航栏位于表格视图的向上部分。
但是,当加载所有数据时,导航栏将向下。
我想在tableview的上方保留导航栏。 我哪里错了?如何解决这个问题呢?
我认为,FirstViewController.swift并不重要,但我正在共享所有代码。
FirstViewController.swift
Tag
答案 0 :(得分:1)
答案 1 :(得分:1)
问题是您已将NavigationBar
从Object library
拖放到ViewController
,因此请将其删除。如果您想将NavigationBar
嵌入YourViewController
显示为UINavigtionController
。
要Embed
ViewController
NavigationConttoller
,请执行以下步骤。
ViewController
Editor
菜单,然后选择嵌入。NavigationController
要将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());
}
}
答案 2 :(得分:0)
按照我的视图尝试在tableview的标题视图中设置导航栏。不会向下移动。