NSOutlineView Image & Text table cell view unable to assign value - objective-c

I have a cell-based NSOutlineView with one "Image & text Table Cell view" in one column. I can assign values to the text-cell via the traditional NSOutlineViewDelegate functions just fine, but I can't figure out how to set an image value to the NSImageCell.
What I've tried:
Link the NSImageCell to a referencing outlet (resulted into an error thrown by Xcode);
Bind the NSImageCell's objectValue to a NSImage #property (results in Xcode deep-frying my CPU while hanging forever on building the storyboard.
It may be a silly thing but what am I not seeing here?

Related

Handling tableview cell selection from other view controllers

I have a tableView with custom table cells which displays a list of sayings. While selecting a cell (say "saying1") from the tableView, the cell will get selected and will moves to next view controller for showing an explanation of selected saying. In that view controller two buttons "Previous" and "Next" are there for navigating to previous and next saying. So user may select next button for seeing next saying (say "saying2"). But the problem here is, In this stage when i navigate back to my tableview, the cell selected will be "saying1" not "saying2".
In order to solve this problem, i collected the currently selected sayings ("saying2's") index from array (ie,index will be 1) and passed it to the previous tableView through segue and converted that value into NSIndexpath. After this step i don't know what to do. Please help me in solving this.
You can specifically select a cell by calling following method present in UITableView class :
selectRowAtIndexPath:animated:scrollPosition:
refere to following link : https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/selectRowAtIndexPath:animated:scrollPosition:

how to identify which cell in tableview clicked

I created tableview that read from url (any cell has name of book) and when clicked any cell gone detailView.
in detail view exist UIScroll that read any image from url and I create it.
but my problem this place. I don't know what read images in UIScroll related any cell.
this is URL : ".../mamal/book.php?p=%d&b=%d"
(p and b display number page and number book)
I want when clicked first cell (book1) compiler gone next page and display images related book1
and etc.
You have to use UITableView protocols <UITableViewDataSource,UITableViewDelegate> in your .h file then use below delegate method which you give which cell is clicked
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"Clicked cell-> %d", indexPath.row);
}
You can also identify the currently selected row using the property indexPathForSelectedRow.
i.e if you want to know the index path of currently selected row at any point of time without using the delegate methods (not saving it during selection) you can use
tableView.indexPathForSelectedRow
If you want to pass around the value between multiple view controller you can declare an instance variable in the view controller you want the value to be passed and store tableView.indexPathForSelectedRow in this variable during initialization. A quick search on so should help you with that.

NSTableView selected row highlight

I have a NSTableView with two columns, one is NSButtonCell and the other is a NSTextFieldCell. The text in NSTextFieldCell cannot be edited but the user can select a part of the text and make it bold. The current implementation is to allow them to do a double click and select a part of the text. The problem is, once the user is done bolding, the highlight color at selected row still persists.
The NSTableView usually has variable number of rows each time. I cannot do SelectRow as false as I need to be able to select the row. I also need to support 10.5.8 so I cannot set - NSTableViewSelectionHighlightStyle as None.
My application is a Cocoa application, which needs to run on 10.5.8, 10.6 and 10.7.
You can try setting the selected row as false. NSTableView has a method deselectRow. After bolding is done, you can deselect the row.

How to populate the table view cell with values entered in another view controller?

I have a custom table view cell, which consists of four labels and an image view. I have another UIViewController which consists of two text fields and one text view.
When the values are entered in the text fields and text view of this controller, and the save button is pressed, the values must be saved on to my custom table view cells' text labels. How is this possible?
Update your data source object with the values and call reloadData function on tableview instance
- (void)reloadData
Call as below
[myTableView reloadData];
EDITED:
First : you could use the delegate concept of Objective-C,
Second: you could store the text value in user default using NSUserDefault and access that in other view controller,
See the very good blog post on NSUserDefault .
iPhone Programming Tutorial – Saving/Retrieving Data Using NSUserDefaults
Capture the Values entered in the Text Inputs and save them in different NSString variables. Set those values for the Next ViewControllers Input.
For example, declare a NSString in second View Controller Interface and #synthesize that. Before moving from first controller to second controller, set the value for that respective variable.

Can't create an NSImage?

Whenever I do:
xxx = [NSImage imageNamed:#"Package.png"];
xxx loads but it's width and height remain 0. And whenever I try loading it into an NSImageCell I get this error:
NSImageCell's object value must be an NSImage.
Can someone help me out? I've never had this problem before.
Edit: Sorry, I've missed this bit out. So when I do it in the data source delegate it does not work and it shows the above error after 'return cell;'.
NSImageCell* cell = [[NSImageCell alloc] init];
[cell setObjectValue:xxx]; // Using imageNamed doesn't help either
Edit 2: This is becoming aggravating. I don't understand what happened but the image loads height and width properly, but it still complains when I add it to an NSImageCell.
I see—so the table view aspect is relevant after all.
As the data source, your job is to return (and receive, in the case of user editing) the object values for the cells in the columns.
But you're not returning such a value; you're returning a cell. Thus, you're trying to set an image cell (created by the data source) as the value of an image cell (the existing one owned by the column).
The log message suggests that you have already set the column's cell as an image cell when you created the column, so all you need to do now is change your data source to always return the object value for the column, not a cell. For an image column, return the image. For a text column, return the string.
Note that NSTableView does not work like UITableView, where UITableViewCells are UIViews and you have as many cells as rows on the screen; in NSTableView, each NSTableColumn gets one and only one data cell, and that one cell is used to draw that column of every row. The cell draws its object value, which you provide to the cell, which you do by returning it (the object value) from your data source method.
The documentation about controls (an NSTableView is a kind of NSControl) and their cells is the Control and Cell Programming Guide.
My guess is it's returning nil, in which case getting the width/height will return 0.
Try:
xxx = [NSImage imageNamed:#"Package"]; // the extension is not needed on the desktop or iOS 4
and make sure the image is actually being copied into your application's Resources folder!
Having established that you are, in fact, receiving an NSImage instance (not nil) whose width and height are zero, the next step is to determine why that happens.
Can you open Package.png in Preview?
If so: What's its width and height in Preview's Info window? Does it have any resolution (DPI or pixels-per-meter) information? If so, what does that say?
If you crack open your application bundle, can you open that copy of Package.png in Preview?
When you log the description of the image, what's the output?
What's the output of logging the image's representations array? (This should be included in the image's own description, but I include it explicitly in case not.)
What happens if you delete your build folder and re-build?