User clicks on "Remote" button and then the following UITableViewController loads up:
The user then selects any value upon which I call:
[self.navigationController popViewControllerAnimated:YES];
to go back again to the previous UITableViewController (screen shot 1).
How do I add the selected value to the UITableViewController?
I hope I am making sense.
In your remote recipients table view controller, you have the Array with which you are loading the table (say myTestArray). Keep it as a property. And also have a NSInteger property (say selectedRow) which will identify which row user selected. And when you go back to the add recipient table view controller, you can know which row was selected by
[remoteRecipientsController.myTestArray objectAtIndex:remoteRecipientsController.selectedRow];
Or use delegates. Upon row selection the remote recipients will give a call back telling which row was selected.
Update:
If you dont have access to the view controller, use delegates.
You can get both array and the selected row in the delegate method, something as follows:
-(void) remoteRecipient:(RemoteRecipientController *) remoteRecipientController didSelectRow:(NSInteger) row {
// Get the selected row
... = [remoteRecipientController.myTestArray objectAtIndex:row ];
}
Or you can also configure the delegate to just return the selected row (as your string), something as follows:
-(void) remoteRecipient:(RemoteRecipientController *) remoteRecipientController didSelectRow:(NSString *) selectedRecipient {
}
Ofcourse, In this case you need to make remote recipient controller pass the selected row as NSString in the delegate.
Related
I have a TabBarController with two tabs; first is InputViewController and second one is TableviewController.
Input view controller has two text fields when I enter the text, after that I want to receive that text filed value in to TableviewController (in the next tab). It does not receive the value.
Try to use this concept.....
Declare two variables in Second tab that is Tableviewcotroller..
For exa..
NSString *strname;
NSString *straddr;
#property and #synthesize both...
Now, in your *InputViewCotroller*tab, create and initialize object of TableViewcotroller, using this object, access these varibles. Like, you want to get values of textfields.
Tableviewcotroller *objTable = ........
objTable.strname = self.textName.text;
objTable.straddr = self.txtAddr.text;
Implement this concept in your project...Hope this helps you...:)
What ever value you have in input view controller like
NSString*text1=textbox1.text;
NSString*text2=textbox2.tex;
In the method where you are moving to next view you should pass the value to the table view controller like this
DetailViewController*tblViewController=[[DetailViewController alloc]init];
NSString*textValue1=text1;
tblViewController.textValue1=textValue;
[self.navigationController pushViewController:tblViewController];
you should alos have textValue NSString in tableView controller also to assign value
i declared an int value as my imageIndexForSend through the following code in myView class.
int imageIndexForSend;
#property int imageIndexForSend;
#synthesize imageIndexForSend;
after on a button click i am displaying a popover which is PopOver calss.
there is table view with multiple indexes in popover class.when i click on any row in PopOver class table it set myView class imageIndexForSend as
In PopOver
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
myView *obj = [[myView alloc] init];
[obj getImageForSend:indexPath.row];
[staticSceneController release];
}
in myViewClass
-(void)getImageForSend:(int)index{
imageIndexForSend = index;
}
then i am return to myViewClass after dismissing popover (popOver class) and doing some actions in myViewClass.
then i am clicking a send button.but the integer value imageIndexForSend is zero.cant get the old value which i set from PopUp.
can any one tell me a way to get the old imageIndexForSend value.may i know what mistake i done.
First, you name a method with get to set the value, it's bad.
Second, you use a property and synthesize it, so you don't need to rewrite the set method unless you need to have a custom set method.
And finally you create a new view on each selection of tableview cell !
1) Remove your getImageForSend: method, you don't need that with property
2) Instead using : [obj getImageForSend:indexPath.row];, use : obj.imageIndexForSend = indexPath.row;
3) Don't create a new view on each selection, assign the value on the existing view.
A better way to transmit data from your popover to your view (controller ?) is to have a delegate property in your popover class and set it with your view object, create a delegate protocol with a method that is called when a cell is selected in popover with an int argument (the index) then make your view class adopts the protocol and do a obj.imageIndexForSend = argument; in your protocol method.
It seems you're allocating a myView instance and assigning that to a local variable (obj), but then you don't keep a pointer to that new instance anywhere.
From what I understand, you already have an existing instance of myView, so what you need to do is to set the variable on that instance, and not create a new one every time.
Each instance have their own set of variables, so changing it in a new instance won't affect any other instances.
You are instantiating a new MyView whenever the user taps on any row of your UITableView. You should try to access the original MyView instead (or whatever object shall retain that setup value).
Within your popover, you should find a way to access the instance that holds the actual index-value. How exactly that is achieved depends a lot on your implementation.
In other words, do not instantiate something within an object that has a shorter lifetime than the object that will access that very instance.
If you're trying to access the index of the selected row in the UITableView you can just use the following:
int index = [myTableView indexPathForSelectedRow].row;
hi i have a NSTableView in a view controller class
i have added an button named as "Add"
When i click on the button then a new row gets added to the table which is blank using this code:
[myArray addObject:#""];
[myTable reloadData];
[myTable editColumn:0 row:[myArray count]-1 withEvent:nil select:YES];
now when i enter the data after that i press enter key but dont understand as which method is called so that i can update the myArray with the new content
cannot find which method gets invoked
any idea!!
Please help
The setObjectValue: method of NSTableViewDataSource protocol gets called after you finish editing you cell.
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
Override this method to get the value you entered while you edited the cell. The value is passed though the object parameter. You can add that to your array.
I have a value called member id and I want to send it to another view controller, If I place the following in didSelectRowAtIndexPath, The value passes to the variable "member".
int memberIndex = [indexPath indexAtPosition: [indexPath length] - 1];
member = [[tableDataSource2 objectAtIndex: memberIndex] objectForKey:#"Memberid"];
If it is placed in the cellForRow, of course it rewrites with every row created. I have a button in each row that launches a viewController, I want the button action to grab the rows "member" and pass it to the new controller. Is there a "didSelectButton at index path method" or a way to grab that on the fly?
any Ideas would be great. It's the first time I'm adding a button to a UiTableview.
Thanks
Why not use the accessory view? It is a built-in button that you can skin with any image you want to give the UI any kind of feel that is required. Then add this to the table's delegate:
accessoryButtonTappedForRowWithIndexPath: (NSIndexPath *) indexPath{ ... }
You will then be able to call your method on your table data source and launch your secondary view.
Just play with "tag".
Each UIView has an attribute tag (int).
in the cellForRowAtIndexPath :
//create yourButton and then
yourButton.tag = memberIndex;
and when you are using an IBAction just get the sender :
- (IBAction) didSelectButton:(id)sender
{
int memberIndex = ((UIButton *)sender).tag;
//
}
tips : to get the sender when you are setting the action property of your button don't forget the ":"
E.G
action = #selector(didSelectButton:);
how is it possible to tag an iphone cell in order to be able to use in a selected favorite table view. i want to be able to tagg the cell and its remaining content in order to be able to display it properly inside a new table view under a different view controller.
You set a tag with a number and by looking at UIView class ref, you set it with an NSInteger,
so a number to you and me.
tableViewCell.tag = 1
Or you extend UITableView and add your own method like
- (void) setFavorite:(BOOL)ans
{
favorited = ans;
}
- (BOOL) favorite
{
return favorited;
}
And then when you access the table view cell, cast it.
Probably better to make it a property though
#property (nonatmoic, assign, getter=isFavorited) BOOL favorited;