简体   繁体   English

如何在Apple Watch中重新加载视图?

[英]How to reload a view in the apple watch?

Hi every one i have to update instantly from my parent app (iPhone App) and Show the value in the watch App.大家好,我必须从我的父应用程序(iPhone 应用程序)立即更新并在手表应用程序中显示值。 I have to reload the value in the watch screen when ever the apps values get updated.当应用程序值更新时,我必须重新加载手表屏幕中的值。 I have to update from the app and show it in its extension app.我必须从应用程序更新并在其扩展应用程序中显示它。在此处输入图片说明

if change the location in the iPhone app.如果在 iPhone 应用程序中更改位置。 Automatically the values should be changed in watch App.值应在手表应用程序中自动更改。 I'm using App Group and NSUserDefault to share values between these apps.Now i can access values from the watch App but its not get updated automatically.我正在使用App GroupNSUserDefault在这些应用程序之间共享值。现在我可以从手表应用程序访问值,但它不会自动更新。 Thanks in advance提前致谢

You can set a timer and change the contents of labels.您可以设置计时器并更改标签的内容。

In WatchKit (WKInterfaceLabel), setting label's contents is very easy.在 WatchKit (WKInterfaceLabel) 中,设置标签的内容非常简单。 Just use the following code in order to set a new text for labels:只需使用以下代码即可为标签设置新文本:

Swift:迅速:

label1.setText(temperature)

Objective-C:目标-C:

[label1 setText:temperature];

Also you can do the same with pictures, charts etc. Just insert the code said before in a function, and call that function each time the timer finishes its interval time.你也可以对图片、图表等做同样的事情。只需在函数中插入之前所说的代码,并在每次计时器完成其间隔时间时调用该函数。

It's better to set short intervals for timer.最好为计时器设置较短的时间间隔。 Less interval means refreshing faster but more internet usage and battery drain, and longer intervals means refreshing not fast as previous way, but less internet usage and more battery saving.更短的间隔意味着刷新更快,但更多的互联网使用和电池消耗,更长的间隔意味着刷新不像以前的方式快,但更少的互联网使用和更多的电池节省。

You can change the interval in run-time by battery percentage.您可以通过电池百分比更改运行时间间隔。 If it is - for example, less than 20% - you can set longer intervals, and when it is more than 20%, set shorter ones.如果是 - 例如,小于 20% - 你可以设置更长的间隔,当它超过 20% 时,设置更短的间隔。 You can only find Apple Watch battery percentage in watchOS 2, but in both versions you can get iPhone battery percentage by the following code:您只能在 watchOS 2 中找到 Apple Watch 电池百分比,但在两个版本中,您都可以通过以下代码获得 iPhone 电池百分比:

Swift:迅速:

var x = UIDevice.currentDevice().batteryLevel

Objective-C:目标-C:

int x = [UIDevice currentDevice].batteryLevel;

NOTE: Short intervals are from 10ms to 200ms, and long ones are from 200ms to 1s.注:短间隔为 10ms 到 200ms,长间隔为 200ms 到 1s。 (ms = Milliseconds = 0.001 seconds) (毫秒 = 毫秒 = 0.001 秒)

NOTE: You can call the initialization method of the view in timer intervals.注意:您可以按定时器间隔调用视图的初始化方法。

If you want to update view manually, just make a button, and set labels and charts' data (by the code given before) or call the view init method.如果您想手动更新视图,只需创建一个按钮,并设置标签和图表的数据(通过之前给出的代码)或调用视图初始化方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM