Xcode 9.3 Watchkit Crash on Wkinterfacebutton Tap

watch button press crash

From looking at your code i would suggest updating the action function from sender: any to sender: wkinterfacebutton hope this helps!

WKInterfaceTable, WKInterfaceButton and action methods

You will need to wire your InterfaceController to your buttons and then call the appropriate method. It is best to decouple it via a delegate or using a selector, but you can just past your interface controller if needed.

This assumes you wired your WKInterfaceTable object to the property table in your interface controller.

//In your interface controller
- (void)loadTableData
{
NSInteger numRows = <CALC_NUM_ROWS>;

[self.table setNumberOfRows:num withRowType:@"<MY_ROW_TYPE>"];

for (int i = 0; i < num; i++)
{
MyRowController *row = [self.table rowControllerAtIndex:i];

//Here is where you want to wire your interface controller to your row
//You will need to add this method to your row class
[row addSelectionTarget:self action:@selector(myMethodToCall)];

}
}

- (void) myMethodToCall
{
//Do something in your interface controller when a button is selection
}

//Now in your MyRowController
-(void)addSelectionTarget:(id)target action:(SEL)action
{
//You will need to add properties for these.
self.selectionTarget = target;
self.selectionAction = action;
}

//Call this when you want to call back to your interface controller
- (void)fireSelectionAction
{
[self.selectionTarget performSelector:self.selectionAction];

//Or to do it without warnings on ARC
IMP imp = [self.selectionTarget methodForSelector:self.selectionAction];
void (*func)(id, SEL) = (void *)imp;
func(self.selectionTarget, self.selectionAction);

}

set WKInterfaceButton title color - WatchKit

Thanks to ColdLogic for pointing me in the right direction. Its a bit complicated way of changing title color but it works.

NSString *titleStr = @"Next";
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:titleStr];
[attString setAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} range:NSMakeRange(0, attString.string.length)];
//set color
[customBtn setAttributedTitle:attString];

Create WKInterfaceButton with image and left aligned text

While i haven't tried this myself i think what you're looking for to match the watch settings is a table view. Define a table view in the interface controller of your story board and add your image and label to the row(s). There's an example of how to do this in the programming guide for apple kit.

interface does not define view controller class

The view controller is missing the identifier in the storyboard

swift error cannot assign value of type 'interface controller' to type HKWorkoutSessionDelegate'

self doesn't implement HKWorkoutSessionDelegate? You don't show that part of the code.

While you implemented the required methods, you have to change

class InterfaceController: WKInterfaceController {

to be

class InterfaceController: WKInterfaceController, HKWorkoutSessionDelegate {

which tells the compiler that the class implements that protocol.



Related Topics



Leave a reply



Submit