How to change size of PaintCode produced object - iphone

I am a newbie, trying hard to make my first app. I would like to change the size of a (bezierpath) object(?) made by PaintCode by receiving a value from a UISlider. Can anyone help me what is wrong with my code below and how to make it work?
int heightOfBubble = 120;
- (IBAction)widthOfBubble:(id)sender {
NSLog(#"slider value = %f", self.slider.value);
[slider addTarget:self action:#selector(drawRect:) forControlEvents:UIControlEventValueChanged];
}
- (void)drawRect:(CGRect)rect {
label.text = [NSString stringWithFormat:#"%f", self.slider.value];
NSLog(#"slider value = %f", self.slider.value);
[BubbleText10 drawBubbleButtonWithText2:#"안개비 조명은 하예 흔들리는 내 몸을 감싸고~~ 술에 취에 비틀거리는 하~예 나의 모습 이제는 싫어~ 삐리비립" number:12 numberOfWidth:widthOfBubble numberOfHeight:heightOfBubble condition: NO];
And I got the following error;
Mar 19 00:55:45 BubbleText03[44457] <Error>: CGContextRestoreGState: invalid context 0x0. Backtrace:
<+[BubbleText10 drawBubbleButtonWithText2:number:numberOfWidth:numberOfHeight:condition:]+4941>
<-[BubbleView drawRect:]+421>
<-[UIApplication sendAction:to:from:forEvent:]+83>
<-[UIControl sendAction:to:forEvent:]+67>
<-[UIControl _sendActionsForEvents:withEvent:]+444>
<-[UISlider endTrackingWithTouch:withEvent:]+255>
<-[UIControl touchesEnded:withEvent:]+620>
<-[UIWindow _sendTouchesForEvent:]+2747>
<-[UIWindow sendEvent:]+4011>
<-[UIApplication sendEvent:]+371>
<__dispatchPreprocessedEventFromEventQueue+3248>
<__handleEventQueue+4879>
<__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__+17>
<__CFRunLoopDoSources0+556>
<__CFRunLoopRun+918>
<CFRunLoopRunSpecific+420>
<GSEventRunModal+161>
<UIApplicationMain+159>
<main+111>
<start+1>
Many thanks in advance.

Instead of #selector(drawRect:) use #selector(setNeedsDisplay).
Documentation:
- (void)drawRect:(CGRect)rect;
… This method is called when a view is first displayed or when an event occurs that invalidates a visible part of the view. You should never call this method directly yourself. To invalidate part of your view, and thus cause that portion to be redrawn, call the setNeedsDisplay or setNeedsDisplayInRect: method instead.
Even if it says directly yourself and you are not calling it directly yourself, it still applies to your case.
— PaintCode Support

Related

Automatic typing password iphone

In my UIViewController I have 2 textfields. One called passwordtextfield and the other retype. Instead of having people actually retype their passwords I want it to automatically fill it in. Is this possible? I tried something that keeps on crashing.
[_passwordtextfield addTarget:self action:#selector(updateTextField:) forControlEvents:UIControlEventEditingChanged];
- (void)updateTextField:(id)sender{
UITextField *retype = ((UITextField *)_passwordtextfield).text;
}
There is no need to cast your text field. You can assign direct value of your text field.So
Write this line
retypetextfield.text = _passwordtextfield.text;
instead of
UITextField *retype = ((UITextField *)_passwordtextfield).text;
I don't know why you want to do this, as mentioned in the comments, but to answer the question... It looks like you are creating a new UITextField in updateTextField instead of setting the text of one that exists. It should look something like this:
- (void)updateTextField:(id)sender{
retypeFied.Text = _passwordtextfield.text;
}
Substitute whatever you named the pointer to your second field for retypeField.

how to implement shutterstock tiker?

I have tried MKTikcerView , DMScrollingTicker and also made a Custom TickerView but , I am not satisfied with that all. All of them when comes to end string displays blank space.They are have not continuous objects displaying.I also use UITableView to show ticker objects by transforming it to horizontal.But there was also a problem that is some of the cells displaying blank.
The main objective is that , I want a ticker view like pull down shutterStock in iphone.It has continuous and updated objects and very smooth scrolling.
screenshot is given below:
Anyone help me please!
Thanks..!
I have add some improvement in my custom tickerView that displays view objects.Here is the files:
StockTicker.h and StockTicker.m .By using these files you can create continuous object displaying on tickerView and can update data easily.
You can use these files just like UITableView.It has its delegates to pass numberOfView to display on ticker and view that will display at particular index.
Using its delegates as:
#pragma mark- UITickerView delegate method
- (NSInteger)numberOfRowsintickerView:(StockTiker *)tickerView
{
return [objectArray count];
}
- (id)tickerView:(StockTiker*)tickerView cellForRowAtIndex:(int)index
{
return [objectArray objectAtIndex:index];
}
here objectArray is array of UILabels.
You can download SampleProject.

Proper way to declare two parameters in a Objective-C method?

This might be a ridiculous question but I can't find it asked yet here already.
Have a protocol delegate method defined:
- (void)myAddViewController:(MyAddViewController *)myAddViewController
loadGPS:(BOOL)gps loadCamera:(BOOL)camera;
which basically is to determine whether the GPS system is to be loaded or the camera should be loaded.
I call this method via:
[self.delegate myAddViewController:self loadGPS:YES loadCamera:NO];
// or alternatively
[self.delegate myAddViewController:self loadGPS:NO loadCamera:YES];
Inside my implemented method in the delegate we have:
- (void)myAddViewController:(MyAddViewController *)myAddViewController loadGPS:(BOOL)gps loadCamera:(BOOL)camera {
.... .... ...
if (gps) {
......
}
if (camera) {
// camera is ALWAYS nil and never seems to be set?!
.....
}
So why when I call the delegate method with Camera: YES is the camera var always nil? It seems like it is never recognizing my second var yet it doesn't mind compiling? :)
It seems like a waste to pass in two mutually exclusive boolean values to a method.
Perhaps you'd be better with two delegate methods:
[self.delegate myAddGPSViewController:self];
// or alternatively
[self.delegate myAddCameraViewController:self];
because when you're firing the delegate methods, you'll already know whether you want GPS or Camera anyway.
It might have,
declaring 'camera' variable again,
can you paste your method
- (void)myAddViewController:(MyAddViewController *)myAddViewController loadGPS:(BOOL)gps loadCamera:(BOOL)camera {
\here?

Can you make custom events with UIControlEventApplicationReserved?

I have written a subclass of UIControl that tracks a number of gestures that are of interest to me. In the documentation for the UIControlEvents enumeration, it says that there is a range of event numbers called UIControlEventApplicationReserved that is "available for application use." Does this mean that I am free to use this range of numbers for my own custom events?
If so, can someone please tell me how to fire events? The obvious way I can think of to do it is this:
enum {
...
MyCustomEvent = 65,
...
};
...
UIEvent* customEvent;
...
for (id target in [self allTargets])
{
for (NSString* action in [self actionsForTarget:target forControlEvent:MyCustomEvent])
{
[self sendAction:NSSelectorFromString(action) to:target forEvent:customEvent];
}
}
Would that even work?
Okay, this is an old subject but I'm going to add my answer to this. I can't really tell for sure whether you can use this mask for your own application even though I suspect it.
But I can tell you for sure how to use it. For starter this value masks the bits at position 24, 25, 26 and 27. You should write an enum of your own that uses this bits only, for example:
enum {
MyPrimaryActionEvent = 1 << 24,
MySecondaryActionEvent = 1 << 25,
};
Once that is done you can register for these actions:
[myButton addTarget:self action:#selector(someAction:) forControlEvents: MyPrimaryActionEvent];
Every time the action MyPrimaryActionEvent is triggered, self will receive the message someAction:. Now how to trigger that action is up to the button itself. In your own UIControl subclass you can trigger the change as follow:
[self sendActionsForControlEvents:MyPrimaryActionEvent];
This will send all the actions to all the targets registered for MyPrimaryActionEvent event. And you're done.

How to call Objective-C from Javascript?

I have a WebView, and I want to call a view in Objective-C from JavaScript. Does someone know how I can do this?
I have this code in my ViewController:
- (BOOL)webView:(UIWebView *)webView2
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:#":"];
if ([components count] > 1 &&
[(NSString *)[components objectAtIndex:0] isEqualToString:#"myapp"]) {
if([(NSString *)[components objectAtIndex:1] isEqualToString:#"myfunction"])
{
NSLog([components objectAtIndex:2]); [[Airship shared] displayStoreFront]; //<- This is the code to open the Store
NSLog([components objectAtIndex:3]); // param2
// Call your method in Objective-C method using the above...
}
return NO;
}
return YES; // Return YES to make sure regular navigation works as expected.
}
And in Javascript:
function store(event)
{
document.location = "myapp:" + "myfunction:" + param1 + ":" + param2;
}
But nothing happens.
The standard workaround for UIWebView is to set a UIWebViewDelegate, and implement the method webView:shouldStartLoadWithRequest:navigationType:. In your JavaScript code, navigate to some fake URL that encodes the information you want to pass to your app, like, say:
window.location = "fake://myApp/something_happened:param1:param2:param3";
In your delegate method, look for these fake URLs, extract the information you need, take whatever action is appropriate, and return NO to cancel the navigation. It's probably best if you defer any lengthy processing using some flavor of performSelector.
The window.location method of calling objective c from JS isn't recommended. One example of problems: if you make two immediate consecutive calls one is ignored (since you can't change location too quickly) - try it yourself..
I recommend the following alternative approach:
function execute(url)
{
var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", url);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
You call the execute function repeatedly and since each call executes in its own iframe, they should not be ignored when called quickly.
Credits to this guy.
Obliviux,
Your code seems to be perfect.
The reason for the problem is that you must have missed to map the delegate.
Either
Connect the delegate of the webView to the file owner in the .xib file
or
Use webView.delegate = self;
in your viewDidLoad.
Thanks
Like people said here, you have to use the method webView:shouldStartLoadWithRequest:navigationType: from the UIWebviewDelegate.
This api http://code.google.com/p/jsbridge-to-cocoa/ does it for you. It is very lightweight. You can pass images, strings and arrays from javascript to objective-C.
I had an issue with this approach: I wanted to send several messages to the iphone device, but it seemed that they were "overlaped" as they could not process all of them sequentially.
Example: when executing this code:
window.location = "app://action/foo";
window.location = "app://action/bar";
The action foo was never executed.
What I had to do was the following:
waitingForMessage = false;
function MsgProcessed(){
waitingForMessage = false;
}
function SyncLaunchURL(url){
if (waitingForMessage){
setTimeout(function(){SyncLaunchURL(url)},100);
}else{
window.location = url
waitingForMessage = true;
}
}
SyncLaunchURL("app://action/foo");
SyncLaunchURL("app://action/bar");
With this approach, the iphone has to call MsgProcessed() after processing the call. This way works for me, and maybe helps someone with the same problem!
Assuming you're doing an app, you can look at how PhoneGap implements that (or even use it). It's a library that supports back-and-forth communication between JS and OBJ-C. There are other libraries and solutions, as well.
If you're talking about a web app (something the user gets to from Mobile Safari), you can't get to Objective-C from there.
Check this one - understanding XMLHttpRequest responses using this (or other javascript) functions?, it's using objective C to call ajax js function, and get the response after it's done, you know the trick is that webview will be triggered when you change the location in javascript, so you can check the location to know its your javascript call or the real request.
Although this is a very old question now, it keeps getting returned by Google and there is a good answer now: the WebScripting informal protocol. It allows you to expose an objective C object to Javascript.
http://developer.apple.com/library/safari/documentation/appleapplications/Conceptual/SafariJSProgTopics/Tasks/ObjCFromJavaScript.html#//apple_ref/doc/uid/30001215-BBCBFJCD