Xcode: Create a group of outlets - cocoa-touch

This is just a quick question, I have lots of outlets in my code that need to be hidden initially and I want to make it so that in my viewDidLoad I only have to say something along the lines of colourObjects.hidden = YES; rather than individually going through and declaring if they are hidden or not i.e. redColourObject.hidden = YES;
blueColourObjects.hidden = YES;
greenColourObjects.hidden = YES; I would find it very grateful to know if this is possible and how you do it!
Thanks for any help
Hugh

IBOutletCollection is what you need:
#property (nonatomic, strong) IBOutletCollection(UIView) NSArray *stuff;
You can drag as many outlets as you want in it and they'll be there. You can also keep the original references for other purposes. then
for (UIView *view in self.stuff) {
[view setHidden:YES];
}

Sorry but there is not a way to do that. You would have to declare that individually.
What you could do I put them all into one UIView and then hide the UIView which would hide everything in in the UIView.

Related

NSTableView without NSScrollView

I'm thinking to make un-scrollable nstableview.
Is it possible to have a table view without scroll view, or maybe to extract table view from scroll view ?
thanks
I don't know if this is good practice (I'm googling about that - that's how I found your question)(Edit: why wouldn't it be?), but it is possible to get an NSTableView without the NSScrollView: drag out a 'custom view' and set it's identity to NSTableView. There you are! The only thing is you don't get any visual feedback from IB about the tableview. But you can still set outlets (the delegate, datasource etc) in IB. I am afraid you'll have to set UI options (things like 'draws background' and such) from code (at least they don't appear if you use my 'trick').
You could even do it without IB (I found this code on SO, I didn't test it):
MyDataSource *dataSource = [[MyDataSource alloc] init];
NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:#"onlyColumn"];
NSTableView *table = [[NSTableView alloc] initWithFrame: frameWhereTableViewShouldGo];
[table setDataSource:dataSource];
[table addTableColumn:column];
[theViewYouWantATableViewIn addSubview:table];
At least you can implement your NSScrollView-subclass and reimplement its scrollWheel: method.
#interface MyScrollView : NSScrollView
#property (nonatomic) BOOL scrollingEnabled;
#end
#implementation
- (void)scrollWheel:(NSEvent *)event
{
if (self.scrollingEnabled)
[super scrollWheel:event];
}
#end
Did you mean this?
self.tableView.scrollEnabled=NO;

How to implement UITextView.hidden

I'm developing an iOS 5 app.
I can't understand why
myTextView.hidden = YES;
or
myTextView.hidden = NO;
is not working?
I have also tried to use [myTextView setHidden:( ! [myTextView isHidden])];
I have myTextView default set to hidden through IB in the xib.
Any help would be great!
Thanks
Just try: [myTextView setHidden:YES];
Is the connection between the IBOutlet and the UITextView on the Xib file established? That's my best guess for why that's not working.
Edit: I am assuming you have create the UITextView on the Xib and not on the code.
in .h
UITextView *myTextView;
#property(nonatomic, assign) UITextView *myTextView;
in .m
[myTextView setHidden:YES];
One way you could make this operation smoother is to have an image identical to your loading image which overlays your entire view. Mark it as
[self.OverlayView setHidden:false];
so that it overlays your start screen. If you then need to display your start screen then simply set
[self.OverlayView setHidden:true];
this will give you a seamless transition to your login screen (a bit of a cludge but works great!)

UITabbarController default tab highlighted

So I'm attempting to deal with uitabbarcontroller and wanted to have a default tab be selected when the view loads.
I have tried setting the
#property (nonatomic) int selectedIndex;
however this just sets which viewcontroller is being shown, not the actual tabbar being selected
I also tried this line
[self tabBar].selectedItem = [[[self tabBar] items] objectAtIndex:0];
but it crashes as you are not allowed to mutate the tabbar of a tabbarcontroller
Any help with this?
Thanks
So, as discussed in the comments, following code should do what you want:
[self.tabBarController setSelectedIndex:desiredIndex];
Alternatively, you can use:
[self.tabBarController setSelectedViewController:desiredViewController];

What could I add to this code to make it not remove the UIToolbar?

NSArray *subviewsList = [[NSArray alloc] initWithArray:[self.view subviews]];
for (UIView *aView in subviewsList) {
NSLog(#"%#",subviewsList);
if (![aView isEqual:sender]) {
[aView removeFromSuperview];
}
}
[subviewsList release];
I have it not remove the UIButton that you click to actually call this code, however, I haven't figured out how to get it not to remove the UIToolbar that I added to the screen via IB. Any suggestions?
EDIT: I should have been more clear, I'm sorry. The code was done to remove the ton of UIImageViews from the screen. I didn't want it to remove the uibutton that calls the method, or the toolbar.
EDIT:
This works. :)
if (![aView isEqual:sender] && ![aView isKindOfClass:[UIToolbar class]]) {
If ([aView isKindOfClass:[UIToolBar class]]) {
// the view is a uitoolbar
} else {
[aView removeFromSuperView];
}
Send from iphone, maybe syntax errors :) but this let you check if your subview is from a specific class
Hope this helps
Any number of things could be happening. Is your UIToolbar a subview or sublayer of one of the aView's you are removing?
Without knowing what all else is happening in your views (in code or in IB), it's hard to say, but also make sure that if you're adding any views or layers that they're not covering anything up. (Even if something like a UIButton is visible, it may not respond if covered by another view.)

Unable to set text in NSTextView

::Edit::
It works now? haha, maybe I just didn't save my latest IB...who the hell knows.
Thanks!
Hey,
This is my first time playing around with desktop applications (I have experience with iphone applications) and I'm stuck - My text view will not update to show any text:
.m:
#synthesize textView;
NSString *txt = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];
NSLog(#"txt = %#", txt);
[textView setString:txt];
.h:
IBOutlet NSTextView *textView;
}
#property(nonatomic, retain) IBOutlet NSTextView *textView;
And IB says textView -> Text View, so everything looks good:
NSLog above outputs the contents of the url resource Im fetching
So, what am I missing?
Double check if the outlets are done in IB. That's probably the reason (textView is probably nil here).
Where is this setString code being called? It's possible the IB outlet isn't instantiated yet. You can check this with a simple
if (textView) {
NSLog(#"textView is not nil);
} else {
NSLog(#"textView is nil");
}
To be sure that everything is set up when you call this, make sure it's after 'awakeFromNib' is called in any objects created through IB.
See NSNibAwaking Protocal
Can you double check NSTextView properties like isEditable, textColor etc to make sure none of them are set incorrectly.
Other than that the code looks good.
I reconnected everything in IB, saved, rebuilt and it worked...= [