简单的问题:是否有可能将一个堆叠WKInterfaceLabel在另一个的顶部WKInterfaceGroup?我像一个疯子一样拖着我无法让蓝色目标线设置在第一个标签的上方或下方.它会坐在它旁边,向左或向右,但它不会在它的上方或下方.
我正在尝试在类似于主/细节的表行中做一些事情,但我根本无法弄清楚它是否可能.
apple-watch watchkit wkinterfacetable wkinterfacegroup wkinterfacelabel
我正在尝试设置WKInterfaceTable.我跟着苹果文档.我的标签没有获取文本,我在控制台中收到此错误消息:
Cannot specify setter 'setTitle:' for properties of NSObject or WKInterfaceController
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?Objective-C拜托.这是我的代码:
.H
#import <Foundation/Foundation.h>
#import <WatchKit/WatchKit.h>
@interface MainRowType : NSObject
@property (strong, nonatomic) IBOutlet WKInterfaceImage *image;
@property (strong, nonatomic) IBOutlet WKInterfaceLabel *title;
@end
Run Code Online (Sandbox Code Playgroud)
.M
#import "MainRowType.h"
@implementation MainRowType
@end
Run Code Online (Sandbox Code Playgroud)
.H
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
#import "MainRowType.h"
@interface WatchTableController : WKInterfaceController
@property (strong, nonatomic) IBOutlet WKInterfaceTable *tableView;
@property (strong, nonatomic) NSMutableArray *titleArray;
@end
Run Code Online (Sandbox Code Playgroud)
.M
我称这种方法
- (void)configureTableWithData:(NSMutableArray*)dataObjects {
[self.tableView setNumberOfRows:[dataObjects count] withRowType:@"mainRowType"];
for (NSInteger i = 0; i < self.tableView.numberOfRows; …Run Code Online (Sandbox Code Playgroud) 我在故事板中创建了一个推送segue从一个 WKInterfaceTableCell到另一个WKInterfaceController(称为DetailInterfaceController).
当我点击该行时, didSelectRowAtIndex未被调用.
有人知道我哪里错了,我怎么能传递字符串?
TableInterfaceController
didSelectRowAtIndexPath print 语句未被调用
@IBOutlet var table: WKInterfaceTable!
var objectsArray = ["1","2","3"]
var object: String!
override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
self.object = self.objectsArray[rowIndex]
print(" object title: \(self.object)")
}
override func contextForSegueWithIdentifier(segueIdentifier: String) -> AnyObject? {
// You may want to set the context's identifier in Interface Builder and check it here to make sure you're returning data at the proper times
// Return data to be …Run Code Online (Sandbox Code Playgroud) 我有一个WKInterfaceController,我添加了一个表如下:
// .h
@interface InterfaceController : WKInterfaceController
@property (weak, nonatomic) IBOutlet WKInterfaceTable *table;
@end
// .m
- (void)table:(WKInterfaceTable *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"did select");
}
- (void)table:(WKInterfaceTable *)table
didSelectRowAtIndex:(NSInteger)rowIndex{
NSLog(@"did select new");
}
Run Code Online (Sandbox Code Playgroud)
但是这两种方法都没有被调用.我无法找到WKInterfaceTable的任何协议声明,也没有找到表上的任何委托属性.
这里有什么我想念的吗?
我必须在表格行中循环输出3个按钮,按下时它将重定向到相关的详细信息.
问题是如何识别用户点击的按钮?我曾尝试setAccessibilityLabel和setValue forKey,但都不起作用.
默认行高正好适合 42 毫米手表的四行。但是在 38mm 手表上,第四排被切断了。
在IB中,我检查了表格的通用“已安装”;对于图像(例如),这会导致自定义大小,但我没有看到表格行高的任何此类选项。或者我只是使用看起来像 Watch Size Classes 的东西,点击底部的“任何屏幕尺寸”?如果是这样,它将如何与“已安装”设置交互?
我打算四处走走,但一些 SmartPerson™ 可以通过指向正确的方向来提供很多帮助。
FWIW,我见过的所有 Apple 示例代码也都有“38mm 截止”问题。
如何删除WKinterfaceTable行中出现的圆角?
下面的代码是使用viewController实现的,我可以为Apple Watch做同样的事情并添加动画吗?
let filteredSubviews = self.view.subviews.filter({ $0.isKindOfClass(UIImageView) })// 2
for view in filteredSubviews {
// 3
let recognizer = UITapGestureRecognizer(target: self, action:Selector("handleTap:"))
recognizer.numberOfTapsRequired=1
// 4
recognizer.delegate = self
view.addGestureRecognizer(recognizer)
returnedAray=tempArray
//TODO: Add a custom gesture recognizer too
}
Run Code Online (Sandbox Code Playgroud)
我只需要知道WatchKit的addGestureRecognizer(识别器)的替代方案.
如果已经选择了WKInterfaceTable,我想更改一行的颜色.我已经完成了这些步骤,但不知道如何进一步:
override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
let row = tableView.rowControllerAtIndex(rowIndex) as! TableRowObject
}
Run Code Online (Sandbox Code Playgroud)
我希望你们中的某些人可以帮助我做到这一点.
标题总结了它.我已经尝试断开/重新连接所有IBOutlets.这是我在InterfaceController上设置WKInterfaceTable的代码:
func setupLoadingTable () {
self.myTable.setNumberOfRows(1, withRowType:"universalRowID")
for (var i = 0; i<self.myTable.numberOfRows; i++){
var row = self.myTable.rowControllerAtIndex(i) as! UniversalRowView
row.mainTitle.setText("Hello world") //THIS THROWS AN ERROR
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的UniversalRowView的代码,它是我的自定义行类:
import WatchKit
class UniversalRowView: NSObject {
@IBOutlet weak var mainTitle: WKInterfaceLabel!
@IBOutlet weak var subTitle: WKInterfaceLabel!
}
Run Code Online (Sandbox Code Playgroud)
表的IBOutlets已正确连接.Storyboard上的行设置为UniversalRowView类型,并且两个标签的出口都已正确连接.
这条线:
row.mainTitle.setText("Hello world")
Run Code Online (Sandbox Code Playgroud)
抛出以下错误:"致命错误:在解包可选值时意外发现nil"
此外,当我评论该代码时,我没有在模拟器上看到它们出现在故事板上的股票WKInterfaceLabels.我觉得这也是一个错误,但我不知道该怎么做.
编辑:在willActivate()中调用setupLoadingTable()
我有一个WKInterfaceController,WKInterfaceTable其中列出了用户在我的应用中记录的一些事件。
用户可以点击表的一行以查看有关该事件的更多详细信息。为此,我覆盖contextForSegue(withIdentifier:in:rowIndex:)了WKInterfaceController包含该表的,因此,轻按一行以一种WKInterfaceController名为的新形式呈现该行的详细视图EventDetailController。
该modal演示文稿在情节提要中定义。我无法使用push演示文稿,因为WKInterfaceController带有的WKInterfaceTable是WKInterfaceController应用程序顶层多个实例之间的页面。
在中EventDetailController,有一个Delete按钮可以销毁表行代表的记录。
当用户点击“ 删除”按钮时,我会显示一条警报,允许用户确认或取消删除操作。
用户确认记录删除后,EventDetailController由于它不再相关,因此我想将其删除,因为它代表已删除的记录。
点击“ 删除”按钮时,将调用以下IBAction定义:EventDetailController
@IBAction func deleteButtonTapped(_ sender: WKInterfaceButton) {
let deleteAction = WKAlertAction(title: "Delete", style: .destructive) {
// delete the record
// as long as the delete was successful, dismiss the detail view
self.dismiss()
}
let cancelAction = WKAlertAction(title: "Cancel", …Run Code Online (Sandbox Code Playgroud) wkinterfacetable ×11
watchkit ×10
ios ×5
apple-watch ×3
swift ×3
animation ×1
ios8.2 ×1
objective-c ×1
watchos ×1
xcode6 ×1