Separate data from multiple rows in picker view - view

I created picker view with 4 rows, but data in all rows are same. So how could i separate data from each row and use it for calculating?

Perhaps this may work for your problem of not displaying the data? Can't really tell because I can't see what you've already done.
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 4;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent (NSInteger)component{
return rowOneItems.count;
return rowTwoItems.count;
return rowThreeItems.count;
return rowFourItems.count;
}
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if(component == 1)
return[rowTwoItems objectAtIndex:row];
else if(component == 2)
return[rowThreeItems objectAtIndex:row];
else if(component == 3)
return[rowFourItems objectAtIndex:row];
else
return [rowOneItems objectAtIndex:row];
}

Related

Target orientation of iOS6 shouldAutorotate

i want to allow the should rotate, based on the target orientation
[[UIDevice currentDevice] orientation]
however the code above, when used in shouldRotate holds the current (old) orientation, not the target orientation
- (BOOL) shouldAutorotate {
return YES;
}
Okay I figured it out. Return YES in shouldAutorotate always and then do this:
- (NSUInteger)supportedInterfaceOrientations
{
if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) {
// Allow if you can
} else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
// Allow if you can
}
// so on
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
This method should do the trick for you.
The toInterfaceOrientation holds the target orientation.
Apart from returning yes to
-(BOOL)shouldAutorotate
{
return YES;
}
you have to implement
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
Different Masks that are available are:
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown
You may also like to see:
https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations

How to check that current space is Dashboard?

Sample code is
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:#selector(activeSpaceDidChange:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil];
Then
- (void) activeSpaceDidChange:(NSNotification *)aNotification {
// code to check if current workspace is dashboard?
}
I want to check whether the current space is dashboard or not? Any idea?
The first think i have tried is get to the current space id according to this answer: Detecting when a space changes in Spaces in Mac OS X . The problem here is that the key kCGWindowWorkspace is deprecated in OSX 10.8. So there is no direct way to get this information.
In my solution now i check for different windows or owners which are only one the dashboard space or on all other spaces:
The user is on the dashboard if there is one window which kCGWindowName ends with .wdgt/
The user is not on the dashboard if there is one window with kCGWindowName == System Status Item Clone, kCGWindowOwnerName == SystemUIServer | Finder
So why i'm not just using the .wdgt/ check? -- Because if there is now widget on the dashboard this not working
So why i'm using more than one window check? -. Because i'm not jet sure which window is always on all spaces. At least System Status Item Clone and Finder are not always there.
Here my implementation is add this function as category to NSWorkspace
- (BOOL) userIsOnDashboardSpace {
NSArray* windowsInSpace = (__bridge NSArray *) CGWindowListCopyWindowInfo(kCGWindowListOptionAll | kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
NSUInteger indexOfWidget = [windowsInSpace indexOfObjectPassingTest:^BOOL(NSDictionary* obj, NSUInteger idx, BOOL *stop) {
if ([obj objectForKey:(id)kCGWindowName]) {
NSString *name = (NSString *)[obj objectForKey:(id)kCGWindowName];
if ([name isEqualToString:#"System Status Item Clone"]) {
*stop = true;
return false;
}
if ([name hasSuffix:#".wdgt/"]) {
*stop = true;
return true;
}
}
if ([obj objectForKey:(id)kCGWindowOwnerName]) {
NSString *name = (NSString *)[obj objectForKey:(id)kCGWindowOwnerName];
if ([name isEqualToString:#"SystemUIServer"]) {
*stop = true;
return false;
}
if ([name isEqualToString:#"Finder"]) {
*stop = true;
return false;
}
}
return false;
}];
return indexOfWidget != NSNotFound;
}

How to see how many files in draggingPasteboard?

I have a drag operation that only allows to drag a single file, and I want to capture this on "draggingEntered" like so:
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
if ([[sender draggingPasteboard] count]] == 1) {
return NSDragOperationCopy;
}
else {
return NSDragOperationNone;
}
}
But count is not valid method or property, but I can't figure out what to replace it with, so which is the best way to see how many items there are on the draggingPasteboard? Should I get the array of filenames on the draggingPasteboard using something like propertyListForType: NSFilenamsPboardType, and then get the index of that, or is there a more clever way to do this?
If You want to use count You need to use pasteboardItems which is items array who response to count.
It can be done like this:
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
if([[[sender draggingPasteboard] pasteboardItems] count] == 1) {
return NSDragOperationCopy;
}
else {
return NSDragOperationNone;
}
}

Function with no arguments works just fine, with arguments - crashes

it works with no problems:
h file:
- (BOOL) trytoGETURL;
m file
- (BOOL) trytoGETURL {
/ some code here ...
if ([response statusCode] == 200)
return YES;
else
return NO;
}
- (IBAction)ButtonTouchUp:(id)sender {
NSLog(#"button clicked");
if ( [self trytoGETURL]) {
NSLog(#"ok");
} else NSLog(#"problem");
but this crashes:
h file
- (BOOL) trytoGETURL:(NSString *) baseurl Redvalue:(int)red
GreenValue:(int)green BlueValue: (int) blue;
m file
- (BOOL) trytoGETURL:(NSString *) baseurl Redvalue:(int)red
GreenValue:(int)green BlueValue: (int) blue {
if ([response statusCode] == 200)
return YES;
else
return NO;
}
- (IBAction)ButtonTouchUp:(id)sender {
NSLog(#"button clicked");
if ( [self trytoGETURL:#"sd" Redvalue:100 Greenvalue:100 Bluevalue:100]) {
NSLog(#"est takaya stranica");
} else NSLog(#"net takoi stranica");
Xcode also writes: instance method not found!??
and by the way it doesn't help me with when I'm starting to write like usual, why is it so?
Check your capitalization:
trytoGETURL:Redvalue:Greenvalue:Bluevalue:
is most certainly not the same as:
trytoGETURL:RedValue:GreenValue:BlueValue:
it was just a problem with suntax.
trytoGETURL:(NSString *) baseurl - is wrong,
trytoGETURL:(NSString *)baseurl is right. - no space needed.

NSTableView with multiple columns

What is an easy way to set up my NSTableView with multiple columns to only display certain data in one column. I have the IBOutlets set up, but I don't know where to go from there.
Assuming you're not using Cocoa Bindings/Core Data, you can display data in an NSTableView by implementing two methods from the NSTableViewDataSource protocol. Typically your controller will implement the protocol, so open the controller .m file and add these methods to the controller's #implementation:
- (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView {
return 25; // fill this out
}
– (id) tableView:(NSTableView*)tableView
objectValueForTableColumn:(NSTableColumn*)column
row:(int)row {
return row % 3 ? #"Tick..." : #"BOOM!"; // fill this out
}
You need to set the table's dataSource property to the controller. In Interface Builder control-drag from the table view to the controller and set dataSource. Now build and run and you should see your data in the table.
If you only want to fill out one column, add an IBOutlet NSTableColumn* to your controller; let's call it explosiveColumn. In Interface Builder, control-drag from the controller to the column you want to fill in and set explosiveColumn. Then, in tableView:objectValueForTableColumn:row: you can test if the column parameter is the same object as the one that the outlet is set to:
– (id) tableView:(NSTableView*)tableView
objectValueForTableColumn:(NSTableColumn*)column
row:(int)row {
if (column == explosiveColumn) {
return row % 3 ? #"Tick..." : #"BOOM!";
} else {
// other columns blank for now
return nil;
}
}
This tutorial might be useful: http://www.cocoadev.com/index.pl?NSTableViewTutorial
Here's an example using multiple table views with data source methods and a document based application:
#pragma mark - Data Source Methods
- (NSInteger) numberOfRowsInTableView:(NSTableView *)tv
{
if (tv == racerTableView)
return [racerList count];
else if (tv == vehicleTableView)
return [vehicleList count];
else
return 0; // something wrong here...
}
- (id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)col
row:(NSInteger)rowi
{
NSString *colid = [col identifier];
if (tv == racerTableView){
NHRacers *racer = [racerList objectAtIndex:rowi];
return [racer valueForKey:colid];
}
else if (tv == vehicleTableView){
NHVehicles *vehicle = [vehicleList objectAtIndex:rowi];
return [vehicle valueForKey:colid];
}
else
return 0; // something wrong here...
}
- (void)tableView:(NSTableView *)tv setObjectValue:(id)obj forTableColumn:(NSTableColumn *)col row:(NSInteger)rowi
{
NSString *colid = [col identifier];
if (tv == racerTableView) {
NHRacers *racer = [racerList objectAtIndex:rowi];
[racer setValue:obj forKey:colid];
}
else if (tv == vehicleTableView){
NHVehicles *vehicle = [vehicleList objectAtIndex:rowi];
[vehicle setValue:obj forKey:colid];
}
else
nil; // something wrong here...
[self updateChangeCount:NSChangeDone];
}
The tableview datasource outlets are set to the File's Owner and the File's Owner has set vehicleTableView and racerTableView to their respective "Table View" in the IB. The colid key checks the identifier (set in IB by selecting the table view column under the "Identity" drop down, while the "Identity Inspector" is shown). These values were chosen to be the KVC (key coding compliant) properties of the classes being displayed in the table views: use lower case first letter (see apple docs for rest).
For example:
(in NHVehicles.h)
#interface NHVehicles : NSObject
{
NSUInteger entry;
NSString *name;
NSString *vehicleClass;
}
#property NSUInteger entry;
#property NSString *name, *vehicleClass;
#end
(in NHVehicles.m)
#implementation NHVehicles
#synthesize entry, name, vehicleClass;
#end
for this tableView, "entry", "name" and "vehicleClass" would be typed (w/o ") into the identifier fields for their respective columns.
If you don't want to show some data in the class, simply do not enter the key for the column identifier. A word of caution: I am using Xcode 4.5.1 and I noticed that once I had entered a few keys for a particular column identifiers and then changed my mind about and attempted to clear the text, it complained when I deleted the text from the identifier field (I could no longer leave the field blank for the columns that I had edited). This was not difficult to work around, but it was a surprise.

Resources