Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 8 years ago.
Improve this question
As you'll see from the code in the xcode project file there's a compile error at build time.
I'm trying to apply names for the indivudal image using the following code:
labelArray =[[NSArray alloc] initWithObjects:#"one", #"two", #"three", #"four", nil];
cell.label.text = [_labelArray objectAtIndex:indexPath.row];
This is using apples sample code for collection view but the principals are the same for my project.
Here's a drop box link for the compile error issue using an NSArray with a uilabel..
The error is:
Interface storyboard compile error.
Any thoughts on this would be great.
Cheers
I don't kwow about your storyboard issue (it is impossible to say anything without seeing the storyboard, or, at least, how the outlet is bound), but there is another issue.
It seems like labelArray is an array of UILabel. But in the first line of your code, you are creating an array of NSString.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 days ago.
Improve this question
I am trying to print a div content with scrollable table. I used ngx-print ver 1.2.1. When I use [useExistingCss] property the scrollable content is not printing, and when I remove that property scroll works properly. Also I tried using styleSheetFile for adding the css files, but styles are not being copied. Not sure what I am doing wrong.. :(
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I'm trying to get to grips with Objective-C, having programmed in Java and C in the past.
I have a class, Unzip, which contains the following method:
- (void)unzipFile:(NSString*)fileName
I'm trying to call this method from the AppDelegate class, to respond to a button click, using the following code, which creates an instance of Unzip and calls the unzipFile method with a string value, but nothing happens.
- (IBAction)unzipIt:(id)sender {
NSLog(#"Unzip clicked");
NSString *zipString = [_testField stringValue];
NSLog(#"Calling unzip with the string %#", zipString);
Unzip *unzip;
[unzip unzipFile:(zipString)];
}
The actual button click works, because the two initial NSLogs appear, but nothing further happens. The method is fine as I've tested it elsewhere so at least something should happen. Could anybody please tell me where I'm going wrong?
Thanks for your time.
You didn't allocate Unzip:
Unzip *unzip = [[Unzip alloc] init];
[unzip unzipFile:zipString];
The reason why it is not working, but not blowing up, is in Objective C, it is safe to send a message to nil.
Some more concepts about Objective C, especially in the section Working with Nil.
You have to initialize your unzip variable
Unzip *unzip = [[Unzip alloc] init];
There is also a shortcut:
Unzip *unzip = [Unzip new];
which is equivalent shorthand.
This question already has answers here:
How to handle with a default URL scheme
(5 answers)
Closed 9 years ago.
how can I make it so that if the URL is myapp://foo that it will preform an action and if it is myapp://bar it will preform a different action.
I've gotten this far with my other question here
Help is very much appreciated.
Once you have your URL scheme registered inside your application, you should be able to capture the URL used to open your application with something like this
- (void)handleURLEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent {
NSString *calledURL = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSLog(#"%#", calledURL);
// Split and do something with calledURL
}
Once you have that URL you should easily be able to split it and determine what you want to do.
There is another question on exactly this as well.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am porting a chrome/opera extension to safari. It shows a popover with some data relative to the page. So it needs to communicate with the injected script. I figured out how to communicate between the injected script and background page and popover and background page. But the popover's event listener is not triggered, the popover sends message to injected script and the return message is not received. Maybe I set it for the wrong window object? Or there is a bug in Safari's popover implementation?
Thank you.
Here is the code.
In the popover:
safari.self.addEventListener("message", (function(theMessageEvent){
safari.extension.globalPage.contentWindow.console.log("popover message");
//this is the listener that is not called
}));
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("get");
//this works and sends message to injected script
in the injected script:
safari.self.addEventListener("message", (function(theMessageEvent){
if(theMessageEvent.name=="get"){
theMessageEvent.target.tab.dispatchMessage("setpopover");
//this sends the message back, maybe the target.tab should be changed to something else?
}
}
EDIT:
I found one solution: the popover send message to the injected script, the injected script sends reply to the background page, and the background page directly calls functions from script in the popover using safari.extension.popovers[0].contentWindow.somefunction();
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
got a quick question for you (pretty much the title): is the book Cocoa Programming for Mac OS X (3rd Edition) outdated?
It's just that I read a little in it, until page 36 (in a .PDF ebook version) where I came across a problem. The chapter introduces you to Objective-C and Cocoa, and you already have to write a program by yourself. Exciting. But when he makes a class called Foo.h and Foo.m, my Xcode doesn't follow the guide.
His Interface Builder is different from my Interface Builder.
When he is about to make outlets and actions, I can't do it. They just won't show up.
I am sure I entered the correct info in my Foo.h file:
#import <Cocoa/Cocoa.h>
#interface Foo : NSObject {
IBOutlet NSTextField *textField;
}
-(IBAction)seed:(id)sender;
-(IBAction)generate:(id)sender;
#end
the Foo.m file:
#import "Foo.h"
#implementation Foo
#end
and I dragged them both to the "Class" folder,
but it still won't show them in IB.
Besides that, Xcode shows three warnings:
Incomplete implementation of class 'Foo'
Method definition for '-generate:' not found
Method definition for '-seed:' not found
This is why I think the book is outdated, but these are not errors, just warnings.
Here's some screenies:
This just made me think that the book might be outdated, and if I can use it all (if there are mistakes in every chapters).
Is it me that made a stupid mistake, or is the book really outdated?
Please help me out on this one, as I really want to learn Objective-C and Cocoa :)
Thank you.
No it's not outdated, you should just keep on reading and a few pages later you will find the instructions to write the definition of the generate: and seed: methods. The lack of that definition is what the compiler is complaining about.
From the "How to read this book" section: "Usually the help you seek will be only a paragraph or two away". ;-)
The book worked fine when I started building apps on Snow Leopard. A few things like "NIB" vs. "XIB" crop up, but the concepts are the same. Now on to your problem.
You won't see any connections in the Identity tab for your class when using a version of Interface Builder that is later than was used in the book. You want the connections tab for that.
Best I can tell from your screenshots, your class is in IB but the connections aren't listed. Are you actually referencing the correct class? Perhaps you have a few "foo.h" files floating around and grabbed the wrong one. Here's how to tell. Open the Library window in IB if it's not already open. In the search box at the bottom, type "foo".
In the pulldown that says "Inheritance", change it to "Definitions". You'll see something similar to this:
If it doesn't say "2 actions, and 1 outlet", you've got the wrong file (I know your file works because I pasted it in to write this up). Confirm the contents of the file that IB is using by clicking "foo.h". That will open the file in Xcode. Make sure it contains what you think it contains.
Yeah, I haven't read that book but Fernando offers sound advice. Read on, you haven't implemented the methods. If you just want to make the compiler happy, you could change the code to:
#import "Foo.h"
#implementation Foo
-(IBAction)seed:(id)sender {
}
-(IBAction)generate:(id)sender {
}
#end
But that doesn't do anything yet. :)