passing the value of a uitextfield from a view to another - xcode

I want to pass the value entered in a UITextfield into another view. and this value shud appear in the UItextfield of second view. IBoutlet,propery,synthesize everything is written correctly. still i am not getting the value in the second view.
My code,
from first view it is passing like this
firstview.txtname1.text=name1.text;
from second view it is accepting like this
player_name1.text=txtname1.text;
can anybody tell me where i went wrong?

First you have to declare the property and synthesize in the secondviewcontroller.
in secondview.h
#property(nonatomic,retain) NSString *str;
in secondview.m
#synthesize str;
And then when you are going from first view to second view do like this.
secondviewobj.name = textfield.text;

Related

Can't change column width in response to outlineViewItemDidExpand

I want to update the column width to the width of the widest entry whenever a node in my NSOutlineView is expanded. Thus, my delegate listens to outlineViewItemDidExpand and calls
[column setWidth:maxColumnWidth];
in it. maxColumnWidth is the width of the widest entry.
However, for some reason, calling setWidth from inside outlineViewItemDidExpand doesn't seem to do anything. When I call it later, e.g. as a response to a button click, it works just fine, but from within outlineViewItemDidExpand it just does nothing.
So any idea what I could do to update the column width whenever the user clicks on an expander icon? Thanks a lot!
If autoresizesOutlineColumn is YES (default) then the outline view resizes the outline column after outlineViewItemDidExpand. Solution: set autoresizesOutlineColumn to NO.
I was able to solve this by calling setWidth() from a selector called by performSelector() from within outlineViewItemDidExpand, like so:
-(void) setColumnWidth
{
[theColumn setWidth:...];
}
-(void) outlineViewItemDidExpand:(NSNotification*)notification
{
// calling setWidth() here doesn't work
// [theColumn setWidth:...];
// but calling setWidth() from a selector works!
[self performSelector:#selector(setColumnWidth) withObject:nil afterDelay:0.0];
}
Don't ask me why calling setWidth() only works from within a selector but it actually does...

how to set text in second View Controller

I thought this would be a no brainer, but it turns out I have spent about 5 hours on this now.
I have two ViewControllers and I want to pass a pre formatted NSString to another VC, using a IBAction called putInfo. All this action is responsible for is putting a word into a label on another VC, .
so, in the first ViewController, I implemented the code like this :
- (IBAction)putInfo:(id)sender {
((secondViewController *)self.presentingViewController).ouputLabel.text = #"chicken";
}
I have tried other things like-grabbing a reference to the second VC, instantiating the second view controller, doing that thing where you initialize the second VC WithNibName--all that. ABove is just my latest failure.
This seems like it should be such a no brainer. any suggestions?
If you're using Storyboard, you'll need to use the method prepareForSegue.
But first you need to put a name to your segue: click on it, go to Attribute Inspector and write an Identifier name for the segue.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier]isEqualToString:#"mySegue"])
{
secondViewController* second = segue.destinationViewController;
second.outputLabel = txtFieldSecondViewController;
}
}
You pass the value of a textField(or some string) to another NSString object of the second view.

UIPickerView with one object

I am using a UIPickerView and currently their is only a single object in it. How can I display that single object on label.
It has this weird property that when we use pickerView the data is not set selected by default.Once we choose another object or roll it, then only any particular object is selected. Hence if only one object is their in pickerView. It does not count as selected even though when you tap on that single object.
I tried a lot but found that if their are more than one object then only you can display the selected object on label but not if their is only one object.
You need to make a code that is triggered when the UIPickerView changes, like this:
#pragma
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
//Action that triggers following code:
{
NSString *nameString = [nameOnMutubaleArrayYouWannaGetDataFrom objectAtIndex:[picker selectedRowInComponent:0]]; //Or 1 if u have multiple rows
NSString *labelString = [[NSString alloc]initWithFormat:
#" %# ", nameString];
labelOutput.text = labelString;
Hope this helps.

Unable to get tab order working within NSPopover

I have a View within an NSPopover, and I am unable to set the tab order correctly. I have set the nextKeyView within my 4 text fields. But it tends to flip from TextField1 to Search1, instead of TextField1 -> TextField2. I have tried inserting [self.view.window makeFirstResponder:textField1] also [self.view.window setInitialFirstResponder:textField1] along with recalculatekeyviewloop but with no luck.
Any help would be much appreciated.
I had a similiar problem when composing the popover-view of certain subviews programatically in awakeFromNIB. I could solve the problem by inserting the subviews after the popover had its private NSPopoverWindow set (i.e. it was shown the first time). It seems like the popover is re-evaluating the view-loop when the popover-view is embedded in the private child-window - ignoring the view-loop given in the view.
You could try the following:
-(void) popoverDidShow:(NSNotification *)notification{ // NSPopoverDelegate-method
if (!popoverDidShowForTheFirstTime){
[self setUpViews];
}...
-(void) setUpViews{
popoverDidShowForTheFirstTime = YES;
// insert views and establish nextKeyViews ...

NSTableView rowViewAtRow: always returning nil

I'm trying to display an NSPopover with additional information to a selected row of an NSTableView. For that I need to get a reference to the view representation of the selected row so I can "attach" my popover to it:
NSInteger row = [[self membersTableView] selectedRow];
NSTableRowView *aView = [[self membersTableView] rowViewAtRow: row makeIfNecessary: YES];
[self setQuickLookPopoverController: [QuickLookPopoverController showPopoverFor: anObject at: aView]];
In the above, the result of aView is always nil. According to Apple documentation, this is the method to obtain a view object, given a selected row. Especially the last sentence of the discussion is a bit weird:
Discussion This method will first attempt to return a currently
displayed view in the visible area. If there is no visible view, and
makeIfNecessary is YES, a prepared temporary view is returned. If
makeIfNecessary is NO, and the view is not visible, nil will be
returned.
In general, makeIfNecessary should be YES if you require a resulting
view, and NO if you only want to update properties on a view only if
it is available (generally this means it is visible).
An exception will be thrown if row is not within the numberOfRows. The
returned result should generally not be held onto for longer than the
current run loop cycle. It is better to call
rowViewAtRow:makeIfNecessary: whenever a view is required..
Why is this method always returning nil?
Solved it. I used NSTableView's method (NSRect) rectOfRow: (NSInteger) rowIndex which will give the frame of the required row.
Thanks for showing me the right direction, I had the same problem! I ended up doing the following, but note that I disabled selection of empty rows and that the following code is inside an IBAction:
[popOver showRelativeToRect:[sender bounds]
ofView:[sender rowViewAtRow:[sender selectedRow]
makeIfNecessary:YES]
preferredEdge:NSMaxXEdge];

Resources