NSTableView with images - nstableview

I have NSTableView with 3 tabs.
Now, I want an image inside every tab, how can i do ?
I must use NSImage with position, so ?
NSImage *theImage;
theImage = [NSImage imageNamed#"myImage.png"];

you can do like this:
in code create one NSMutableArray with property and synthesize
header file:
#property (readwrite, retain) NSMutableArray *imageArray
implementation file:
#synthesize imageArray
do like this wherever you want to add image to array:
NSMutableDictionary *imageDict = [NSMutableDictionary dictionary];
[imageDict setObject:[NSImage imageNamed:#"ABC"] forKey:#"image1"];
[imageDict setObject:[NSImage imageNamed:#"XYZ"] forKey:#"image2"];
[imageDict setObject:[NSImage imageNamed:#"XYZ"] forKey:#"image3"];
[imageArray imageDict];
[self setImageArray:imageArray];
take array controller in XIb, bind arraycontroller to imageArray array, bind table column with the array controller with given key path (here keypath is image1,image2 and image3).
one More thing take image name without extension . drag and drop image cell on tableview cell

Related

How do I create something that works like a logging control in Xamarin.Forms

I'm after something like the application output window in Visual Studio, like so:
I'd like to be able to:
bind to an ObservableCollection of strings
select and copy text (as shown in the screenshot above)
At present this is for a Mac app, although iOS may follow later.
I've tried these:
Editor - Problem is it only exposes a Text property that I can bind to and not a collection. Sooner or later, the maximum string length will be reached.
ListView with Label for ViewCell - Problem is text from a Label is not selectable, let alone having multiple lines (bound collection items) selectable.
Using a custom renderer for Mac that makes use of NSTextView and appending to textStorage every time a new item is added, but again, there’s a limit to how much you can add to textStorage.
I'm open to using third-party tools such as Syncfusion, if that makes it easier.
Custom a method to deal with list data to combine them into a newline string :
public string formatstring(NSArray objects)
{
StringBuilder stringBuilder = new StringBuilder();
for(nuint i=0;i< objects.Count; i++)
{
stringBuilder.Append(objects.GetItem<NSString>(i) +"\n");
}
return stringBuilder.ToString();
}
Then used in NSTextView as follow :
string[] items = new string[] {"111111" , "222222" , "333333" , "444444" , "555555" };
NSArray array = NSArray.FromStrings(items);
NSTextView textView = new NSTextView(new CGRect(100,160,200,100));
textView.BackgroundColor = NSColor.Gray;
textView.Value = formatstring(array);
View.AddSubview(textView);
The effect :

Can't programmatically bind NSImageView in view-based NSTablveView cellView

I have a view-based NSTableView which is a single column with a custom CellView containing about a dozen text fields and a single NSImageView.
-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
ComboTableCellView* view = [tableView makeViewWithIdentifier:[tableColumn identifier] owner:nil];
// I bind the text fields with:
[[view nameView] bind:NSValueBinding toObject:view withKeyPath:#"objectValue.name" options:nil];
// I bind the NSImageView with:
NSMutableDictionary* statusOptions = [[[NSMutableDictionary alloc] initWithCapacity:0] autorelease];
[options setObject:kStatusIconTransformerName forKey:NSValueTransformerNameBindingOption];
[[view statusView] bind:NSValueBinding toObject:view withKeyPath:#"objectValue.status" options:statusOptions];
return (view);
}
My transformer takes "status" which is an NSNumber and returns an NSImage because status will be a number from 1 to 4. This works in a cell based NSTableView with an NSImage column.
However, in my view-based NSTableView I get:
Cannot remove an observer (NSAutounbinderObservance 0x600000028ac0) for the key path "objectValue.status" from (ComboTableCellView 0x6180001e3e00), most likely because the value for the key "objectValue" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the ComboTableCellView class.
How can I correctly bind an NSImageView that is within a reuseable view used as the row/cellview in a view-based NStableView?

Is there a way to access ALAssets information outside of resultBlock?

Okay so I have my ImagePicker all setup and the ALAssetLibrary setup to get the Picture and Title (if it exists for existing pictures or generic text for a new picture) but now I'm trying to figure out if there's a way I can access this information outside of the block call from the assetForURL method. So here's my code just so I can show what's happening (this is in the viewDidLoad method of a screen that is displayed after a picture selection is made)
__block NSString *documentName;
__block UIImage *docImage;
NSURL *resourceURL = [imageInfo objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset)
{
ALAssetRepresentation *imageRep = [asset defaultRepresentation];
//Get Image
CGImageRef iref = [imageRep fullResolutionImage];
//If image is null then it's a new picture from Camera
if (iref == NULL) {
docImage = [imageInfo objectForKey:UIImagePickerControllerOriginalImage];
documentName = #"New Picture";
}
else {
docImage = [UIImage imageWithCGImage:iref];
documentName = [imageRep filename];
}
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary *imageAsset = [[ALAssetsLibrary alloc] init];
[imageAsset assetForURL:resourceURL resultBlock:resultblock failureBlock:nil];
Now I want to be able to use the two variables (documentName and docImage) elsewhere in this ViewController (for example if someone wants to change the name of the document before they save it I want to be able to revert back to the default name) but I can't seem to figure out what I need to do so these variables can be used later. Don't know if this makes much sense or not, so if I need to clarify anything else let me know.
Okay so I figured out that the problem wasn't with the code but with my logic on how I was using it. I was trying to do this on the Modal View that was presented after an image was selected instead of just doing this in the ImagePicker screen and then calling the Modal window inside of the result block code.

UITextField not setting NSString

I have a pickerView in a popOver.
When the user selects a row from the pickerView, it should be stored into a UITextField (subject)
The method i'm having troubles is:
- (void) viewWithPickerController:(ViewWithPickerController*) viewWithPickerController didSelectValue:(NSString*) value
{ NSLog(#"selected value is: %#",value);
subject.text = [NSString stringWithFormat:#"%#",value];
NSLog(#"subject is: %#",subject.text);
}
Where value is the row of the pickerView: it logs the right value but it doesn't set it to the textField subject, which seems to be null.
Where am i wrong?
You need to make sure your "subject" IBOutlet is set.
If you're doing this picker view method before your XIB / view controller is instantiated, that would explain why subject is a nil object.
How else would you be instantiating "subject"?

Please explain me how to control a Table View in Cocoa?

I search Google to find a good answer but the most tutorials are shown in previous Xcode Versions...
Also, I don't want to drag-n-drop cells from the Interface Builder, but to control the Table View programmatically (from an NSObject subclass file).
What I currently do is this: 1. Create a file named tableController.h that is a subclass of NSObject.
2. I create an NSObject Object in my Nib File (and set it as a subclass of tableController).
3. I drag a Table View to my window.
4. I CTRL+Drag from the Table View to my tableController.h so to create the outlet "tableView"
5. I create these functions in the interface file:
-(int)numberOfRowsInTableView:(NSTableView *)cocoaTV;
-(id)tableView:(NSTableView *)cocoaTV:objectValueForTableCollumn:(NSTableColumn *)tableCollumn row:(int)row;
6. I implement the functions like this:
-(int)numberOfRowsInTableView:(NSTableView *)cocoaTV{
return 5;
}
-(id)tableView:(NSTableView *)cocoaTV:objectValueForTableCollumn:(NSTableColumn *)tableCollumn row:(int)row{
NSArray *tvArray = [[NSArray alloc]initWithObjects:#"1",#"2",#"3",#"4",#"5", nil];
NSString *v = [tvArray objectAtIndex:row];
return v;
}
Then I CTRL+Drag from the Object in the Interface Builder to the Table View to set the dataSource and to set it as delegate.
When I build and Run the App it shows that it has created the 5 Rows but in every cell in every column it says "Table View Cell".
Any help would be appreciated....
-(id)tableView:(NSTableView *)cocoaTV:objectValueForTableCollumn:(NSTableColumn *)tableCollumn row:(int)row is wrong.. i'm not sure how it compiles, to be honest (unless there was an error copy/pasting it). the method should look like:
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSArray *tvArray = [[NSArray alloc]initWithObjects:#"1",#"2",#"3",#"4",#"5", nil];
NSString *v = [tvArray objectAtIndex:row];
return v;
}

Resources