I have a method which need receive a Byte[] :
In the .h file:
- (void)setPC1_APPKEY:(Byte[] )pC1_APPKEY;
In the .m file:
I want to own a Byte[] property to save it.
But when I declare the property like this:
#property (nonatomic, assign) Byte PC1_APPKEY[];
It shows error:property cannot have array or function type'Byte[]'
And so I set it to attribute like this:
{
Byte PC1_APPKEY[];
}
It shows error:Field has Incomplete type ‘Byte[]’
How can I get the Byte[] ? thanks.
you can use Pointer like this
#property (nonatomic, assign) Byte *PC1_APPKEY;
all files
.h
//
// ocViewController.h
// testTableViewHeader
//
// Created by 刷脸卡 on 10/11/16.
// Copyright © 2016 曾祥林. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface TestViewController : UIViewController
- (void)setPC1_APPKEY:(Byte[] )pC1_APPKEY;
#end
.m
//
// ocViewController.m
// testTableViewHeader
//
// Created by 刷脸卡 on 10/11/16.
// Copyright © 2016 曾祥林. All rights reserved.
//
#import "TestViewController.h"
#interface TestViewController ()
#property (nonatomic, assign) Byte *PC1_APPKEY;
#end
#implementation TestViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *testString = #"1234567890";
NSData *testData = [testString dataUsingEncoding: NSUTF8StringEncoding];
self.PC1_APPKEY = (Byte *)[testData bytes];
for(int i=0;i<[testData length];i++){
printf("testByte = %d\n",self.PC1_APPKEY[i]);
}
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setPC1_APPKEY:(Byte [])pC1_APPKEY{
self.PC1_APPKEY = pC1_APPKEY;
}
#end
Related
// FilePiece1
// the form of import module No.1
// AController.m
#import Module;
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
SubA *info = [[SubA alloc] init];
info.uid = 100;
NSLog(#"%lu", (unsigned long)info.uid);
}
#end
// FilePiece2
// the form of import module No.2
// AController.m
#import Module.subHeadA;
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
SubA *info = [[SubA alloc] init];
info.uid = 100;
NSLog(#"%lu", (unsigned long)info.uid);
}
#end
// FilePiece3
// header file of SubA
// Module/subHeadA.h
#interface SubA
#property (nonatomic, assign) UInt32 uid;
#end
// FilePiece4
// header file of SubB, before the change
// Module/subHeadB.h
#interface SubB
#property (nonatomic, assign) UInt32 kk0;
#end
// FilePiece5
// header file of SubB, after the change
// Module/subHeadB.h
#interface SubB
#property (nonatomic, assign) UInt32 kk0;
#property (nonatomic, assign) UInt32 kk1;
#end
If I need to use SubA in ViewController (FilePiece1), and SubB change between two builds (FilePiece4&5), will there be a difference in build performance between two builds? Can Xcode take advantage of the build cache of the first time (FilePiece4) in both import ways (FilePiece1&2)?
Build Process Description:
the first build
FilePiece1/2
FilePiece3
FilePiece4
the second build
FilePiece1/2
FilePiece3
FilePiece5
Ok so I am attempting to pass an int to another interface, edit the int and give it back to the original interface. I am trying to use a delegate to achieve this and I believe I have it setup correctly and it appears the method is not being called when its supposed to.
//
// InterfaceController.h
// DelegateTest WatchKit Extension
//
// Created by Rohan Hodge on 20/10/2015.
// Copyright © 2015 Hodge Development. All rights reserved.
//
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
#import "SecondController.h"
#interface InterfaceController : WKInterfaceController <DelegateTest>
{
NSTimer *Update;
}
#property (strong, nonatomic) IBOutlet WKInterfaceLabel *FirstControllerLabel;
#property (nonatomic,assign) int FirstInteger;
#property (nonatomic,assign) int RecievedInteger;
#property (nonatomic,assign) NSString *PassString;
#end
// InterfaceController.m
// DelegateTest WatchKit Extension
//
// Created by Rohan Hodge on 20/10/2015.
// Copyright © 2015 Hodge Development. All rights reserved.
//
#import "InterfaceController.h"
#interface InterfaceController()
#end
#implementation InterfaceController
#synthesize FirstInteger;
#synthesize RecievedInteger;
#synthesize PassString;
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
// Configure interface objects here.
}
-(void)UpdateVoid
{
self.FirstControllerLabel.text = [NSString stringWithFormat:#"%i", FirstInteger];
}
- (void)willActivate {
SecondController *interfaceController;
interfaceController.delegate = self;
Update = [NSTimer timerWithTimeInterval:1.0 target:self selector:#selector(UpdateVoid) userInfo:nil repeats:YES];
// This method is called when watch view controller is about to be visible to user
[super willActivate];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
-(void)DelegateMethod:(int)ReturningInt
{
[self popController];
FirstInteger = ReturningInt;
self.FirstControllerLabel.text = [NSString stringWithFormat:#"%i", FirstInteger];
}
- (IBAction)UpButton {
FirstInteger++;
self.FirstControllerLabel.text = [NSString stringWithFormat:#"%i", FirstInteger];
}
- (IBAction)DownButton {
FirstInteger--;
self.FirstControllerLabel.text = [NSString stringWithFormat:#"%i", FirstInteger];
}
- (IBAction)PassDataButton {
PassString = [NSString stringWithFormat:#"%i", FirstInteger];
[self pushControllerWithName:#"SecondController" context:PassString];
}
#end
//
// SecondController.h
// DelegateTest
//
// Created by Rohan Hodge on 20/10/2015.
// Copyright © 2015 Hodge Development. All rights reserved.
//
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
//This declaration of delegate.
#protocol DelegateTest <NSObject>
-(void) DelegateMethod:(int)ReturningInt;
#end
#interface SecondController : WKInterfaceController
{
id delegate;
}
#property (nonatomic, assign) id <DelegateTest> delegate;
#property (strong, nonatomic) IBOutlet WKInterfaceLabel *SecondLabel;
#property (nonatomic,assign) NSString *RecievedString;
#property (nonatomic, assign) int FirstReceivedInteger;
#end
//
// SecondController.m
// DelegateTest
//
// Created by Rohan Hodge on 20/10/2015.
// Copyright © 2015 Hodge Development. All rights reserved.
//
#import "SecondController.h"
#import "InterfaceController.h"
#interface SecondController ()
#end
#implementation SecondController
#synthesize SecondLabel;
#synthesize FirstReceivedInteger;
#synthesize RecievedString;
#synthesize delegate = _delegate;
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
//This is where I receive the int inside of a string and split it from the string so I can change it
RecievedString = context;
FirstReceivedInteger = [RecievedString intValue];
// Configure interface objects here.
}
- (void)willActivate {
self.SecondLabel.text = [NSString stringWithFormat:#"%i",FirstReceivedInteger];
// This method is called when watch view controller is about to be visible to user
[super willActivate];
}
- (IBAction)UpButton {
FirstReceivedInteger++;
self.SecondLabel.text = [NSString stringWithFormat:#"%i",FirstReceivedInteger];
}
- (IBAction)DownButton {
FirstReceivedInteger--;
self.SecondLabel.text = [NSString stringWithFormat:#"%i",FirstReceivedInteger];
}
//This is a button that is ment to pass back the int.
- (IBAction)ReturnToOriginalInterface:(id)sender{
[self.delegate DelegateMethod:FirstReceivedInteger];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
#end
I'm new to Stack Overflow, Sorry about the messy code formatting.
P.S I use the Arrow in the top left of the interface to return to the original Interface. Also am using Objective-C
Thanks in advance.
You need to set a property or method to change in your controller (that your first controller will change) and you get back the result with a delegate pattern.
You're attempting to do this in a Watch app, yes? I don't know that delegates don't work, but when I did this for my Watch app, I used the context parameter of WKInterfaceController::presentControllerWithName:context:.
context is a NSDictionary of the values you want to pass around. One of those values could be a pointer to the presenting controller.
So, trying to decipher what you're attempting in your app, I believe the proper thing to do is:
In the ORIGINAL WKInterfaceController:
- (IBAction)buttonThatOpensOtherIC
{
NSDictionary *context = #{
#"firstController" : self,
};
[self pushControllerWithName:#"Other IC"
context:context];
}
}
In the OTHER WKInterfaceController:
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
if (context)
{
self.originalInterfaceController = context[#"firstController"];
}
}
//This is the button that calls the delegate method.
- (IBAction)ReturnToOriginalInterface:(id)sender
{
// [self.delegate DelegateMethod:FirstReceivedInteger];
if (self.originalInterfaceController) {
self.originalInterfaceController.firstInteger = self.returningInt;
}
[self popController];
}
*Note the use of awakeWithContext: in the OTHER interface controller.
DISCLAIMER #1: I haven't executed this code, so there may be a typo in it. It is an adaptation for you of working code I do use.
DISCLAIMER #2: I haven't updated my app for WatchOS 2. I doubt this part of things changed, but it is possible.
my project won't show the web view no matter what code i try use. I even tried a youtube tutorial. I know this question has been asked many times but it doesn't make sense to me. I used this tutorial https://www.youtube.com/watch?v=AmMF7hWrYZk
Heres my code
If you need more detail please ask me. I'm knew to objective c
ViewController.m
// FirstViewController.m
// Have Your Say
//
// Created by Cormac on 11/1/14.
// Copyright (c) 2014 MK Software Corporation. All rights reserved.
//
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"http://google.com"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestURL];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
ViewController.h
//
// FirstViewController.h
// Have Your Say
//
// Created by Cormac on 11/1/14.
// Copyright (c) 2014 MK Software Corporation. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController
#property (nonatomic, strong) IBOutlet UIWebView *webView;
#end
I'm working on my first ground-up iOS app. I'm sure I'm doing something wrong here, but I can't seem to ferret out the problem.
I have an app with some IBActions in it, which do two things:
1) Outputs some simple text via NSLog (to let me know the action worked) - this works okay (it outputs my text via NSLog)
2) Makes a call to a method in a custom class which should also output an NSLog statement. - this doesn't work (no text output via NSLog)
I'm also struggling a bit with where to create the instances of my classes so that they are accessible elsewhere in my code.
Here's the code:
//
// ViewController.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Player.h"
#import "Orc.h"
#interface ViewController : UIViewController {
// Variables that you want to access globally go here?
Player *wizard;
Orc *grunty;
}
-(IBAction)takePie:(id)sender;
-(IBAction)castFireball:(id)sender;
-(IBAction)attack:(id)sender;
#end
and
//
// ViewController.m
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import "ViewController.h"
#import "Player.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)takePie:(id)sender{
// Player attempts to take the pie
// If Orc's health is > 0, don't let the player take the pie
// If the Orc's health is <= zero, let the player take the pie
NSLog(#"IBAction - player attempted to take the pie.");
[wizard takePie];
}
-(IBAction)castFireball:(id)sender{
NSLog(#"IBAction - player cast fireball.");
[wizard castFireball];
}
-(IBAction)attack:(id)sender{
NSLog(#"IBAction - player attacked.");
[wizard attackOrc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Player *wizard = [[Player alloc]init];
Orc *grunty = [[Orc alloc]init];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
and
//
// Player.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <Foundation/Foundation.h>
#interface Player : NSObject
#property int maxHealth;
#property int currentHealth;
#property int armorClass;
#property int meleeToHitModifier;
-(void)setHeathBar;
-(void)attackOrc;
-(void)castFireball;
-(void)takePie;
#end
and
//
// Player.m
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import "Player.h"
#implementation Player
#synthesize maxHealth;
#synthesize currentHealth;
#synthesize armorClass;
#synthesize meleeToHitModifier;
-(void)setHealthBar {
NSLog(#"Player health is 15");
return;
}
-(void)attackOrc {
// roll a d20
// add the "to hit" modifier
// compare the result to the orc's armor class
NSLog(#"Player - Player attached the Orc");
return;
}
-(void)castFireball{
NSLog(#"Player - Player casts Fireball");
return;
}
-(void)takePie{
NSLog(#"Player - Player attempts to take pie");
return;
}
#end
Note: I also have an Orc class defined, but it looks fairly identical to the player class shown.
Thanks in advance for the help!
-- Eddie
Your ViewController.h (which you should call by some more distinctive name, FYI) should look like this:
//
// ViewController.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Player.h"
#import "Orc.h"
#interface ViewController : UIViewController
#property Player *wizard;
#property Orc *grunty;
-(IBAction)takePie:(id)sender;
-(IBAction)castFireball:(id)sender;
-(IBAction)attack:(id)sender;
#end
Then in your ViewController.m, your viewDidLoadMethod should look like:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.wizard = [[Player alloc]init];
self.grunty = [[Orc alloc]init];
}
This should at least ensure you have an instantiated instance of Player that you can call methods on, so your NSLog should be reached.
I have a UILabel(descriptionOfProgram) on a second ViewController(GraphViewController) that needs to be set when the segue from the original MVC occurs.
Currently, in my main MVC, I do two things in my prepareForSegue::
I set an #property NSString in GraphVewController to the string I want it to be.
I set descriptionOfProgram's text to be equal to that string by calling a function in GraphViewController setDescriptionLabel:.
When graphViewController comes on string, the text is not in the label. During testing, I created a button called test in GraphViewController to call setDescriptionLabel when pressed. This worked. Any ideas on what's going on?
I included GraphViewController.h and .m in the second MVC, and GraphingCalculatorViewController.m in the Main MVC.
GraphViewController.h:
//
// GraphViewController.h
// GraphingCalculator
//
// Created by Graham Gaylor on 3/1/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface GraphViewController : UIViewController
#property (nonatomic,copy) NSArray *program;
#property (nonatomic,weak) NSString *description;
#property (weak, nonatomic) IBOutlet UILabel *descriptionOfProgram;
- (IBAction)test:(id)sender;
- (void)setDescriptionLabel:(NSString *)description;
#end
GraphViewController.m:
//
// GraphViewController.m
// GraphingCalculator
//
// Created by Graham Gaylor on 3/1/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "GraphViewController.h"
#import "GraphView.h"
#interface GraphViewController() <GraphViewDataSource>
#property (nonatomic, weak) IBOutlet GraphView *graphView;
#end
#implementation GraphViewController
#synthesize program = _program;
#synthesize descriptionOfProgram = _descriptionOfProgram;
#synthesize description = _description;
#synthesize graphView = _graphView;
- (void)setProgram:(NSArray *)program
{
_program = program;
[self.graphView setNeedsDisplay]; // any time our Model changes, redraw our View
self.graphView.dataSource = self; // setting graphView delegate GraphVC
}
- (IBAction)test:(id)sender {
self.descriptionOfProgram.text = #"test";
[self setDescriptionLabel:self.description];
}
- (void)setDescriptionLabel:(NSString *)description
{
NSLog(#"Got into setDescriptionLabel");
self.descriptionOfProgram.text = #"hello";
}
- (NSArray *)programForGraphView:(GraphView *)sender {
return self.program;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)viewDidUnload {
[self setDescriptionOfProgram:nil];
[super viewDidUnload];
}
#end
This is my main MVC. I got rid of all the extra functions that don't deal with the seque.
GraphingCalculatorViewController.m:
//
// GraphingCalculatorViewController.m
// GraphingCalculator
//
// Created by Graham Gaylor on 3/1/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "GraphingCalculatorViewController.h"
#import "GraphViewController.h"
#interface GraphingCalculatorViewController()
#property (nonatomic,strong) NSArray *programToGraph;
#end
#implementation GraphingCalculatorViewController
#synthesize programToGraph = _programToGraph;
- (void)setAndShowGraph:(NSArray *)program {
self.programToGraph = program;
[self performSegueWithIdentifier:#"ShowGraph" sender:self];
NSLog(#"setAndShowGraph");
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:#"ShowGraph"]) {
[segue.destinationViewController setProgram:self.programToGraph]; // sets GraphVC's program to current program
[segue.destinationViewController setDescriptionLabel:[CalculatorBrain descriptionOfProgram:self.programToGraph]];
NSLog(#"prepareForSegue");
}
}
- (IBAction)graphPressed {
[self setAndShowGraph:self.brain.program];
}
- (void)viewDidUnload {
[self setVariablesUsed:nil];
[super viewDidUnload];
}
#end
prepareForSegue: is called before viewDidLoad: so your IBOutlet will be nil. Try setting the incoming value to a NSString and then use that string to populate the label on viewDidLoad: