UITextField text not changing on the UI - uitextfield

Once the code bellow is executed, the textfield's text doesn't change in the UI to "Fly" but the second NSLog does print "TextField: Fly" as it should.
#property (strong, nonatomic) IBOutlet UITextField *typeTextField;
....
UITableViewCell* cell = [self.theTableView dequeueReusableCellWithIdentifier:#"TypeCell"];
self.typeTextField = (UITextField*)[cell viewWithTag:1];
NSLog(#"TextField: %# ", self.typeTextField.text);
self.typeTextField.text = #"Fly";
NSLog(#"TextField: %# ", self.typeTextField.text);
Any help would be much appreciated.

You almost definitely forgot to connect the outlet for the UITextField in interface builder. Bring up the .xib file that that typeTextField is visible in, click on typeTextField, then show the Utility pane (the one on the far right in Xcode 4+). Click the Connections Inspector (the one that looks like a right arrow) and drag a New Referencing Outlet to your File's Owner.
When you don't connect the UITextField you drew in Interface Builder with the IBOutlet that you identified in your source file, both UITextFields get created as separate entities. You can make changes and work with the valid typeTextField with a broken IBOutlet, but it'll never appear on your view.
Consult How to connect an IBOutlet from an UITableViewController directly to custom cell? and http://www.youtube.com/watch?v=d_kO-J3DYvc on properly wiring your custom UITableViewCell objects.

Related

Xcode 4.3: duplicated connections of an IBOutlet

I am learning Stanford CS193p course with Xcode 4.3.3. I think the screenshot below is pretty much self-explaining. But i will describe the problem with words anyway.
I control-drag a UILabel from storyboard to corresponding implementation file to make the IBOutlet #property. Then I see two connections displayed when clicking the filled circle in the left side of the editor where shows line numbers. I don't know how to delete it.
Moreover, I see only ONE connection in storyboard's connections inspector of the UIlabel.
More weird, when I try to set the UILabel's text inside the setter of a public preperty, it fails to update the label's text:
-(void) setQuestion:(NSString *)question
{
_question = question;
self.questionLabel.text = question;
NSLog(#"The quesion is %#",question);
NSLog(#"The quesion label text is %#",self.questionLabel.text);
}
I use two NSLog to debug and get the following. It shows the NSString *question is #"What do you want your label to say?", yet the self.questionLabel.text is null. The value assign fails. I suspect this relate to the duplicated connections thing mentioned above.
2012-07-29 04:03:53.817 Kitchen Sink[18628:f803] The quesion is What
do you want your label to say?
2012-07-29 04:03:53.820 Kitchen
Sink[18628:f803] The quesion label text is (null)
The following is the screenshot showing the duplicated connections. I am probably missing something obvious, please help.
I would stalk this up to Xcode storyboard wonkiness.
First, try a clean of the project and a re-build.
Should you still have that problem, manually define the #property without dragging from the AskerViewController view to the AskerViewController implementation (.m) file by doing the following.
Cut that IBOutlet #property line in the interface section of the implementation (.m) file for AskerViewController. Click the label in storyboard. Disconnect any binding that label to the AskerViewController. Clean the project. Then, paste back in the property, and control-drag from the label to the view controller orb at the bottom of the AskerViewController view in your storyboard file.

Can't CTRL+Drag NSButton to custom NSView header

I'd like to create a custom NSTableCellView instantiated by Interface Builder. I've set my Table Cell View class to MyTableCellView, and properly created MyTableCellView : NSTableCellView .m/.h files.
However, I just can't CTRL+Drag a simple button from inside this view to MyTableCellView.h in order to create an IBOutlet.
Here is a video to show what happens: http://youtu.be/sNNbuVT-SZs.
How the view is subclassed:
How I try to CTRL+Drag a button
Also, sometimes, Interface Builder just don't allow the cell view's class to be modified. What's happening ?
I finally found a solution, that is a little weird but works as expected. Instead of connecting the NSButton to MyTableCellView header directly, I used the reversed path:
Manually create an outlet:
#property(retain, nonatomic) IBOutlet NSButton* button;
Then click the empty circle on the left, and drag it to your XIB file's button:
I have no idea why it works this way, please let me know if you know the anwser.

Can't change Text Label on Sheet

I've created a sheet which I would like to display various messages while the program is doing data crunching. The sheet opens and closes correctly and I have a Text Label on the sheet which is connected to my main controller (the owner of the sheet) with an IB Outlet.
The Nib loads correctly, open and closes correctly, but the static text label is never updated. The connected IBOutlet was defined this way:
IBOutlet id mySheetText;
The call I am using to try and modify the text on the sheet is this:
[mySheetText setStringValue:#"Some text message..."];
This format works fine if the Label is in the main window, but does nothing if the Label is on the sheet.
All the connections in IB appear to be correct. I'm sure that I'm missing something very simple, and i'm guessing that it has something to do with the fact that the sheet is a different "window" than the main window, but I can't seem to find anything in the docs to point me in the right direction.
Incidentally, here is the way I connected the sheet...
NSWindow *mySheet;
#property (assign) IBOutlet NSWindow *mySheet;
#synthesize mySheet;
...and opened it:
if (!serverSyncSheet) {
[NSBundle loadNibNamed:#"mySheetNibFile" owner:self];
}
[NSApp beginSheet: self.mySheet
modalForWindow: [[NSApp delegate] mainWindow]
modalDelegate: self
didEndSelector: NULL
contextInfo: NULL];
Any ideas?
* EDIT *
Ok, so it turns out that I am partially correct. If I attempt to read the text value, it turns out that it IS setting it to the correct text, but the sheet is not being updated to DISPLAY the change. I suspect that I need to tell the window to redraw... never done that before. Back to the docs to see if I can find it. If anyone knows the method to call, let me know. :) Thanks!
Well, my suspicions were correct... it was something simple.
I just had to redraw the window:
[mySheet display];
Doh! :)

IBOutlets not showing

I created three IBOutlets in a .h but when I go to Interface Builder and go to Referencing Outlets or right click on the object that I want to connect to one of the outlets. It just doesn't display the outlets I made. How do I find and connect the images in IB to these. My goal is to make custom buttons, I have the images out in IB and have set the highlighted state. And I want the images to auto switch to the highlighted state when touchupInside is triggered.
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController {
IBOutlet UIButton *brown
IBOutlet UIButton *red
IBOutlet UIButton *blue
}
-(void)brownPressed
-(void)redPressed
-(void)bluePressed
#end
If the code you posted is accurate, you are missing 6 semicolons. Interface Builder won't be able to properly parse the header file without them and so it won't show any IBOutlets.
Try changing the code to the following:
#interface FirstViewController : UIViewController {
IBOutlet UIButton *brown;
IBOutlet UIButton *red;
IBOutlet UIButton *blue;
}
-(void)brownPressed;
-(void)redPressed;
-(void)bluePressed;
#end
This answer is in reference to Xcode 4
If you changed the name of the .xib manually, don't forget to check these IB setting in the right pane:
Identity and Type: File Name
should be:
newName.xib
Custom Class : Class
should be:
newName
...
I was also experiencing this problem - after changing the .xib filename manually. I have no idea why renaming by refactoring was grayed out but that was my first attempted solution to rename. I then made some IBOutlets, but dragging to the File's Owner didn't give me any options to connect to it.
I right clicked on File's Owner and noticed some warnings telling me there was no IBOutlet by the name of the variable it tried to reference.
Basically, since I changed the .xib filename manually, at least one of the above configurations did not automatically follow (makes sense since I did a manual operation).
This happens to me try connecting the touch up inside connection of the button to files owner and then it will show up

Uitableview within uiview

I have Uitable view within uiview with navigation bar , I want to add button to the navigation bar to edit the contents of uitableview
any suggestion how to do that please
I think that you want to place your UITableView controller within a UINavigationController (see the UINavigationController class reference for more information).
In your UIViewController for the UITableView, you need to override the methods found under the "Configuring a Navigation Interface" section of the Apple Developer Documentation.
Within this section of methods lies - (UIBarButtonItem *)editButtonItem, which you could override to provide the button for your editing purpose. Under the hood, the UINavigationController will call this method to get the edit button for its user interface. Using this technique ensures that your app stays consistant with the user expierence iOS users have come to love.
There is solution that I tried and worked for me. The solution is
in .h file
UIBarButtonItem *edit;
and set property line as
#property (nonatomic , retain) IBOutlet UIbarButtonItem *edit;
in .m file
in your action handler of the button add
[self.tableView setEditing:TRUE];
Open the .xib file of your view controller and add a UIBarButtonItem either to left or right side of the Navigation Bar and connect the respective IBOutlet to edit button and also the selector method.
Now in the delgate of tableView add the following method
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
//sets the editing style for every row.
return UITableViewCellEditingStyleDelete;
}
Now you can play around with the UITableViewDelegate Methods and also the above methos to get the desired functionality.
Hope it works and do communicate if it does!!

Resources