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
Dynamically Set Properties from Dictionary<String, Any> in Swift
F# Asynchronous Http Request - Parse JSON Response
Generating Random Doable Math Problems Swift
Tvos Button Inside Navigationlink Is Not Working
Can Not Get Correct Position of View in Swiftui
Flattened Objects in JSON File to Nested Object Structure in Swift
How to Make First Responder in Swiftui Macos
Load a Spritekit Scene from Another Bundle
My UIcollectionview Does Not Scroll Smoothly Using Swift
Implement a Crosshair Kind Behaviour in Realitykit
Public Default Init in Protocol
Swiftui - How to Change The Button's Image on Click
Upload Multiple Images to Ftp Server in iOS
Why Cannot Read The Receipt Data for On-Device Validation
How to Use Nscalendar Range Function Within Calendar
How to Use This Fetchrequest() in Swift
Spritekit How to Create and Transition to Different Scenes (Swift Language)