UITextView setText works only once - cocoa-touch

I have a UITextView in my xib and in my UIViewController class, I call setText on this element. It works correctly - once.
Subsequently, it does not set the text and the old text remains.
I also have the same problem with UINavigationBar, where navBar.topItem.title can be set once but not again.
How do I clear the old values and get the new values to show?
Thanks
DeShawn

Does 'subsequently' mean 'on the next line of code' or 'the next time a button is clicked' ?
The latter is appropriate I guess, don't you set your outlet to nil somewhere ?

Related

NSOutlineView Image & Text table cell view unable to assign value

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?

Update main view with change in tableView subview

I have a tableView sub view on my Main view controller. Here's a screenshot: https://www.dropbox.com/s/mp5r9eiv8tg3fmj/Screenshot%202015-02-03%2018.58.24.png?dl=0
I want to update the "remaining" labels when a row is either inserted or deleted. The problem comes when I call my "setLabels" method in controller didChangeObject: delete and insertRowAtIndexPaths. With this (https://www.dropbox.com/s/fcj8h3a03pfud6x/Screenshot%202015-02-04%2019.11.46.png?dl=0 ) implementation the labels only update when the next cycle comes. (If i add one, nothing will happen until I add another or delete one. I'm left with the label values that correspond to the tableView before the most recent change. Always one step behind)
I added an NSLog to verify the method is being called (it is) so I have no idea why my labels won't update till controllerWillChangeContent is called for a second time.
PS: my set labels method is simple. It uses my "getSum" method which gets the sum of an entities attribute and sets the label

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 "insert" text into UITextField?

I'm trying to insert a text into a UITextField. But by insert, I mean replacing the character at cursor position with the new one (insert button's functionality on windows).
If I manually replace the incoming string and do setText (with NO returned to shouldChangeCharactersInRange method), the cursor moves to the end of textField.
For UITextField (iOS 3.2+), try:
[textField replaceRange:[textField selectedTextRange] withText:toInsert];
You can replace the text as you have done previously and restore the position of your caret. Note that this can only be done with UITextView rather than UITextField (that would require a lot more unjustified work, unless you absolutely have to use UITextField):
NSRange selectionRange = myTextView.selectedRange;
myTextView.text = myNewText;
myTextView.selectedRange = selectionRange;
You have to note that it's a good idea to check the validity of selectionRange variable for new text - make sure that cursor position isn't greater than the new text length.

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?