NSArray and Sandbox Question - nsarray

I don't quite understand, but basically I am trying to click a button and have a value added to my NSMutableArray myArray which is a property. I thought my method that would be called when a button is pressed would be something like:
- (IBAction)addInterval {
NSString *string = #"test";
[self.myArray addObject:string];
}
But I don't understand why this doesn't work?
Also, is Wifi, volume control, and bluetooth all not in our sandbox to be used?thanks.

In general, in order for your IBAction to get called, it must have a parameter, e.g.
-(IBAction) addInterval: (id)sender {
}
Also, make sure you have bound the action to the button correctly inside the UI Designer - you should see it as an action outlet for the button.
To make sure your method is being called, stick a line in the method like:
NSLog(#"Called addInterval action");
Bluetooth will not work in sandbox, WiFi will work in the sense that the network connection will function, and the reachability example should help you here.

Could be one of a few things but the classic problem here is forgetting to connect the button to the action in interface builder. Have you checked that?
I'm also assuming that you've synthesized the myArray property so that you can use the dot notation.

Related

Qt wizard back button Ui issue

I'm new with Qt and I'm making a little application. I've do it with QWizard and QWizardPages.
I Have added 2 CustomButtons to the wizard so it has 5 buttons down: ButA, ButB, Back, Next/Finish, and Cancel.
ButA and ButB don't have to appear in all WizardPages. Eg:
WP0: just ButB
WP1: ButA and ButB
To do that, I have:
void WP0::initializePage()
{
wizard()->button(QWizard::CustomButton1)->setVisible(false);
}
With that when the app starts, you can't see butA. BUT if you go to the next page (where you see ButA and ButB) and then you click on BackButton, then you see ButA in WP0.
I supose that then you click on BackButton there is no call to WP0::initializePage() so my question is: how or where should I call that wizard()->button(QWizard::CustomButton1)->setVisible(false);
to never see ButA on WP0 ? Or what should I do?
I don't know if I understand your question completely. your description is kind of complicated. I think you should try button's events. It means you should call this function in press event or something like that and it's better that you define a boolean variable for true or false and call it by reference. I think this should solve your problem.

In iOS how do I change the text of a button, from a class other than viewController?

I would like to change the text of my UIBarButtonItem from another class (objective-C++) that I use in my project.
I have an IBOutlet myButton setup in myViewController and I can successfully do something like:
[ myButton setTitle:#"newTitle" ];
in myViewController.mm
Now I would like to do the same but from myCppClass that I use in my project.
Is there a way for myCppClass to access myViewController's myButton?
Shall I use some type of delegation mechanism?
I am pretty new to Ios and objective-C.
Thanks,
Baba
Create a method within your myViewController class to change the button title, then call that method from myCppClass by following the instructions described in this answer:
How to call method from one class in another (iOS)
https://stackoverflow.com/a/9731162/2274694
The short answer is, don't. You should treat a view controller's views as private. Instead, add a method to your VC like changeButtonTitle. Then call that method from from your other class.
The answers above are correct, but from your comments I suspect you aren't yet happy.
If you are super lazy, and you don't mind the string being the same in all instances of the VC (which in practice is usually the case) you could simply write a getter and setter for the string name as a class variable in the destination class. That way you don't even need access to the actual instance of the class, just its name. Tacky but super easy.
As others have pointed out, don't try and modify the buttons on a different VC directly. Pass a message and have the owning VC do it when it loads.
Well, passing messages forwards (to a new VC) is very easy. At the bottom of every VC class code there is #pragma navigation section commented out which gives you a handle to the destination VC. Cast it to the proper type and you set properties in the destination VC instance. In your case, create a public property NSString which holds the button text in your destination VC, and set it in your navigation section. This could be any class, or even a delegate, but a simple string should work.
Passing messages backwards (to previous VCs) can work the same way but it starts to get messy. You can programatically step back through the stack of VCs to find a particular (instance of) a VC. One of the answers to Get to UIViewController from UIView? gives sample code for stepping back through view controllers.
But if its simply forward communication, passing messages or information through
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
at the bottom of the VC code and the commented out lines below is very easy and safe.

MFC WebBrowser Control: How many (normal) lines of code does it take to simulate Ctrl+N?

Update: Answer: Two normal lines of code required. Thanks Noseratio!
I banged my head on the keyboard for more hours than I would have cared to trying to simulate IEs Ctrl+N behavior in my hosted Browser control app. Unfortunately, due to complications which I've abstracted out of my code examples below, I can't just let IE do Ctlr+N itself. So I have to do it manually.
Keep in mind that I am running a hosted browser. So typically, opening links in new windows will actuall open it within a new "tab" within my application (it's not really a tab, but another window... but appearance-wise it's a tab). However, Ctrl+N is different -- here, it is expected a fully-fledged IE window will launch when pressed.
I think my problem is that of framing the questions -- admittedly I am new to WebBrowser control and I find it to be a lot of yucky. Regardless, I've scoured the Internet for the past day and couldn't come up with an elegant solution.
Basically, the ideal solution would be to call a "NewWindow" function within WebBrowser control or its affiliate libraries; however, all I was able to find where the *On*NewWindow methods, which were event handlers, not event signallers. Which I understand that most of the time, the user will be creating the events... but what about programmatic simulation?
I tried looking into an SENDMESSAGE approach where I could use the IDs that the OnNewWindow events use... that ended up in nothing than crashes. Perhaps I could go back to get it work, but I'd like confirmation is that approach is even worth my time.
The next approach, which should have been the most elegeant, but sadly didn't pan out, was like the following:
Navigate2(GetLocationURL().GetBuffer(), BrowserNavConstants::navOpenInNewWindow);
It would have worked marvelously if it weren't for the fact that the new window would open in the background, blinking in the taskbar. needing clicking to bring it to the front.
I tried to get around the limitation in a myriad of ways, including getting the dispatcher of the current context, then calling OnNewWindow2 with that IDispatch object. Then I would invoke QueryInterface on the dispatch object for an IWebBrowser control. The webBrowser control (presumably under the control of the new window) could then navigate to the page of the original context. However... this too was a pretty messy solution and in the end would cause crashes.
Finally, I resorted to manually invoking JavaScript to get the desired behavior. Really?? Was there really no more elegant a solution to my problem than the below mess of code?
if ((pMsg->wParam == 'N') && (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_SHIFT) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
{
LPDISPATCH pDisp = CHtmlView::GetHtmlDocument();
IHTMLDocument2 *pDoc;
if (SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2, (void **)&pDoc)))
{
IHTMLWindow2* pWnd;
pDoc->get_parentWindow(&pWnd);
BSTR bStrLang = ::SysAllocString(L"JavaScript");
CString sCode(L"window.open(\"");
sCode.Append(GetLocationURL().GetBuffer());
sCode.Append(L"\");");
BSTR bStrCode = sCode.AllocSysString();
COleVariant retVal;
pWnd->execScript(bStrCode, bStrLang, retVal);
::SysFreeString(bStrLang);
::SysFreeString(bStrCode);
pDoc->Release();
}
pDisp->Release();
I find it hard to believe that I must resort to such hackery as this to get something as simple as opening a new window when the user presses Ctrl+N.
Please stackoverflow, please point out the clearly obvious thing I overlooked.
Ctrl-N in IE starts a new window on the same session. In your case, window.open or webBrowser.Navigate2 will create a window on a new session, because it will be run by iexplore.exe process which is separate from your app. The session is shared per-process, this is how the underlying UrlMon library works. So you'll loose all cookies and authentication cache for the new window. On the other hand, when you create a new window which hosts WebBrowser control within your own app process, you'll keep the session.
If such behavior is OK for your needs, try first your initial Navigate2 approach, precededing it with AllowSetForegroundWindow(ASFW_ANY) call. If the new window still doesn't receive the focus correctly, you can try creating an instance of InternetExplorer.Application out-of-proc COM object, and use the same IWebBrowser2 interface to automate it. Below is a simple C# app which works OK for me, the new window is correctly brought to the foreground, no focus issues. It should not be a problem to do the same with MFC.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace IeApp
{
public partial class MainForm : Form
{
// get the underlying WebBrowser ActiveX object;
// this code depends on SHDocVw.dll COM interop assembly,
// generate SHDocVw.dll: "tlbimp.exe ieframe.dll",
// and add as a reference to the project
public MainForm()
{
InitializeComponent();
}
private void NewWindow_Click(object sender, EventArgs e)
{
AllowSetForegroundWindow(ASFW_ANY);
// could do: var ie = new SHDocVw.InternetExplorer()
var ie = (SHDocVw.InternetExplorer)Activator.CreateInstance(Type.GetTypeFromProgID("InternetExplorer.Application"));
ie.Visible = true;
ie.Navigate("http://www.example.com");
}
const int ASFW_ANY = -1;
[DllImport("user32.dll")]
static extern bool AllowSetForegroundWindow(int dwProcessId);
}
}

What signal should I capture to grab the text of Gtk::Entry before it is changed?

I am writing an application using gtkmm 3 (running Ubuntu 12.04 LTS) and working right now with the Gtk::Entry control.
I cannot find the correct signal to capture so that I can grab the Gtk::Entry buffer text before it is changed, and persist it to maintain a record of changes. I know that in some other tool-kits, there is a hook provided that facilitates such. (I believe using a "shadow buffer".)
What signal do I have to grab to do this? What is the slot's signature for this signal? Is this functionality supported at all?
Since you are changing the behaviour, it's better to inherit from Gtk::Entry:
class ValidatedEntry : public Gtk::Entry {
Glib::ustring last_valid;
virtual void on_changed()
{
Glib::ustring text = get_text();
if (... validation here ...)
set_text(last_valid); // WARNING: will call this on_changed() again
else
last_valid = text;
Gtk::Entry::on_changed(); // propagate down
}
};
BUT
This goes against usability, that's why it's not a built-in behaviour. Users won't like the text reverting back just because they miss-typed something; they might hit backspace before they realize the entry threw the wrong character away.
You should at least wait until the user presses the Enter key (i.e. signal_activate or override on_activate()), or do something less drastic, like showing a warning icon.
You could give a try to GObject's "notify" signal. It is used in conjunction with the property to spy. Connecting to "notify::text" will call your callback for each modification of the "text" property, but the first change may be the setter that will set the initial value, that you could then store. Worth a try.
Otherwise, you could try to store it on the first triggering of the "insert-text" or "delete-text" signals. Please give use some feedback if that seems to work.
I also agree with DanielKO: on an usability point of view, modifying user input is just annoying and bad practice. Better to tell her which field is wrong, put the focus there, and/or have a button to reset to defaults, but not enforce any change on user input.

Can't hide CCMenuItem when using In-App-Purchase

This time I would like to ask if anybody had such strange problem with disabling button (CCMenuItemImage) in cocos2d. I have in-App-Purchase connected and when purchase is done following function is triggered
- (void)productPurchased:(NSNotification *)notification {
[NSObject cancelPreviousPerformRequestsWithTarget:self];
waitingForStore = FALSE;
[loop setVisible:FALSE];
[buyItem setVisible:FALSE];
// setAccessibilityElementsHidden:YES];
NSString *productIdentifier = (NSString *) notification.object;
NSLog(#"Purchased: %#", productIdentifier);
}
waitingForStore = FALSE;
[loop setVisible:FALSE];
This two operation works fine, but the problem is with the third one. I would like to make the 'BUY' button invisible.
[buyItem setVisible:FALSE];
This one does not do anything at this place( the button is still visible and accessible). If I will use it on the other part of code it works just fine- but here .... not. Trying to change position doesn't work neither.
Could it be connected with inAppPurchase thread or something?
I have found the reason. It was my mistake when making two calls to the apple store and creating two buttons. :) So, it could be closed.
I understand your problem. If you you want to disable menuitem you can set menuitem.isEnabled property.
And if you want to hide button, you can set property menuitem.visible = NO.
If this is not working for you can also use [menuitem runaction:[CCFadeOut actionWithDuration:1.0f] ]. Then use FadeIn as per your requirement.
This is alternative option for you.