how to view different detailView of selected row on iOS Master Detail - iphone

I'm working on master detail app and i would like to view different detailView of selected row. and to be my question clear i give you example here:
Master Detail
detail 1 >
detail 2 >
the target is when i press [detail 1 >] give me self detailview of detail 1 row. and press [detail 2] give self detailview of detail 2 row. i think it's clear. also add customize buttons, images inside every detail view if possible!!
any help will be appreciated.

DetailViewController *detailView = [[DetailViewController alloc]init];
detailView.tagValue = 1;
[self.navigationController pushViewController:detailView animated:YES];
You can send a tag value to detailView and based on this value you can show different views.
Like make a property like #property(nonatomic)NSInteger tagValue; in .h class of detailView and synthesize it in .m class. Now you can send the tagValue from master Class like this
Now you can check value of tagValue in DetailViewController and based on this you can create your View.
I think it is clear now. But if you still have any issue, you can write your code.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 
{
    DetailViewController *detailView = [[DetailViewController alloc]init];
     
    detailView.tagValue = indexPath.row;
     
    [self.navigationController pushViewController:detailView animated:YES];
}
we need to give detailView.tagValue = indexPath.row;

Related

iOS 6 pass data from TableView to Detail View

I've a table view with some rows and each row has its Detail Disclosure button.
I want that when the user taps on that button, another table view (customized by storyboard) appears and shows some relative data.
From TableViewController.m
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detailViewController = [[detailViewController alloc] init];
//creating a parse object
PFObject *checkin = [_dataSourceArray objectAtIndex:indexPath.row];
//getting data i want
NSString *trainNumb = [checkin objectForKey:#"trainNumber"];
//passing the data
detailViewController.trainNumber = trainNumb;
}
From the DetailTableViewController.m
- (void)viewDidLoad {
[_trainNumberLabel setText:_trainNumber];
}
The problem is that in the DetailTableView the NSString results to be null.
What I'm missing here? Thank you!
If this code actually compiles, this may be your problem:
DetailViewController *detailViewController = [[detailViewController alloc] init];
It should be:
DetailViewController *detailViewController = [[DetailViewController alloc] init];
But you shouldn't be alloc/initing your view controller in the first place. When you customize a view controller in Interface Builder, you've got to instantiate it like this if you want those customizations:
[self.storyboard instantiateViewControllerWithIdentifier:#"MyStoryboardIdentifier"]`
And you've got to set the controller's storyboard ID to "MyStoryboardIdentifier" or whatever identifier you want to use.
Also, as you've indicated in the comments, you've got a timing issue: your detail controller's viewDidLoad runs before you set the train number. A better approach would be to ensure that it works regardless of the sequence:
- (void)updateTrainNumberLabel
{
self.trainNumberLabel.text = self.trainNumber;
}
- (void)setTrainNumber:(NSString *)trainNumber
{
_trainNumber = trainNumber;
[self updateTrainNumberLabel];
}
- (void)viewDidLoad
{
...
[self updateTrainNumberLabel];
}
In other words, you configure your label in a separate method, in this case updateTrainNumberLabel, and when anything that could affect the label happens, e.g. the view loading or the number being changed, you call the method.

Passing the name of a table cell to detailed view

How would I be able to pass the name of a table cell that is clicked in a Master View Controller to a Detailed View Controller. I would like it to be used later in my detailed view right now though I would like to use this data for the detailed view's navigation item title by means of self.navigationItem.title =. Can anyone please provide basic code to how to make this happen?
Your going to want to use the didselectrowatindexpath method. Something like this, initialize the new view and set the title:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *myDetViewCont = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:[NSBundle mainBundle]];
NSInteger row = indexPath.row;
NSString *title = [ListOfItems objectAtIndex:row];
myDetViewCont.navigationItem.title = title;
[self.navigationController pushViewController:myDetViewCont animated:YES];
}
If you only want to set the navigation title, you can just set it before you push the detailViewController in navigation controllers' stack.
detailViewController.title = #"whatever you want";
If you do need the name of the cell for other places, then make a NSString property in DetailViewController, and set it before pushing.
The easy way is to create a property in the detailed view controller and set it to the title. Then you can use in the ViewDidLoad to set the title.
psuedo code:
create detailed view controller
set property
push it on the navigation bar
grab property in ViewDidLoad

Access a new UIViewController from a UITableViewCell

I have a Tab Bar application with 6 Tab Bar items that each open a UITableView. I am trying to enable each table with the ability to open a Detail View Controller when an item in a row on the table is selected.
For example, for the first ViewController ( ViewController1.m ), I created
DetailView1.xib
DetailViewController1.h
DetailViewController1.m
In order to get each row in ViewController1.m 's TableView, I understand I must
use this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
This is my code for that method, which does not produce any errors or warnings, but nothing sees to happen when the TableViewCell is selected:
DetailViewController1 *dvController = [[DetailViewController1 alloc] initWithNibName:#"DetailView1" bundle:[NSBundle mainBundle]];
[navController pushViewController:dvController animated:YES];
[dvController release];
Should this not load DetailView1.xib? I created this with the Tab Bar Application Template...which has no NavigationController in it by default I believe. Is it possible something is not hooked up right in Interface Builder?
You'd need to configure each tab to contain an instance of UINavigationController with one of your view controllers nested inside of it. Then in tableView:didSelectRowAtIndexPath:, you'd want to change the second line of code in your example to this:
[[self navigationController] pushViewController:dvController animated:YES];

Iphone : How to return a image or anything from second view to first view?

please check the picture you will more clear what I want to present
This is the first launch in First View
It's an empty table view
There is a add button on the right bar
If you press the Add button it will push to the Second View
The second is a only 3 rows table view
Tap the first row it will pop up a alert view to let you set a name
Press create ,the text will appear in the first row
<That's the question 1,I don't know how to pass the text to the cell...>
And keep forward ,That's a custom radio button in the row 2 and row 3
Unless You click the radio button first , otherwise you can't call this methord
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
This is last two view
Icon View 1
Icon View 2
There are many buttons in the view,This the second question:
If I press one of this button,it will return to the second view and show the button icon on the tableview row 2 or row 3
Finally,press the Done button(same on the right bar)
It will back to the First View and show what you type the name , and which icon you selected
(Basis on radio button is selected)
That's the last question.
I upload my source code here:Link
You can download it ...
and here is the code about how I push the view...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row==0) {
[self nameInputAlertView];
}
RadioButtonClass *btn = [radioButtonArray objectAtIndex:[indexPath row]];
if (btn.selected) {
//Radio Button is selected ,use that icon
if (indexPath.row == 1) {
IconViewOne *iconViewOne = [[IconViewOne alloc]init];
iconViewOne.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:iconViewOne animated:YES];
[iconViewOne release];
}
if (indexPath.row==2) {
IconViewTwo *iconViewTwo = [[IconViewTwo alloc]init];
iconViewTwo.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:iconViewTwo animated:YES];
[iconViewTwo release];
}
}
}
so...Summary all the question...
1.How to write a text via textfield in the alert view to table view cell ?
2.How to selected an icon from last view to second view ?
3.Send all this two elements to First view : Name & Icon
I only know how to pass elements from view 1 to view 2...
Don't know how to return back......
Thanks mate , please help me to figure out this problem.I will very very appreciate !
BTW:you can take the radio button class to add in your any project
I dont know this is the correct way or not but i think this may help you.
Since you want to retrieve the name and image in both views declare them in the appdelegate so that it can be accessed globally.
Que 1:
When selecting a row didSelectRow Delegate will be called. In that you will get the IndexPath. Store that indexPath globally. Then
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if ([alertView tag]==1) {
if (buttonIndex == 1){
NSLog(#"Created");
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:tableIndexPath]; //tableIndexpath is declared globally as NSindexpath
ReturnToFirstViewAppDelegate *appObj=(ReturnToFirstViewAppDelegate *)[[UIApplication sharedApplication]delegate];
appObj.selectedName = macroNameSetting.text; //Setting the Name globally
cell.detailTextLabel.text =macroNameSetting.text;
[self.tableView reloadInputViews];
}
}
}
Que 2 and 3
In the AppDelegate declare
NSString *selectedName;
UIImage *selectedImage;
Assign property and synthesize them
In your iconViews
- (void)setIcon : (id)sender{
UIButton *button = (UIButton *)sender;
UIImage *selectedImg = [UIImage imageNamed:[NSString stringWithFormat:#"marco%d",button.tag]];
ReturnToFirstViewAppDelegate *appObj=(ReturnToFirstViewAppDelegate *)[[UIApplication sharedApplication]delegate];
appObj.selectedImage = selectedImg;
// push your viewcontroller
}
In any Viewcontroller access them as
ReturnToFirstViewAppDelegate *appObj=(ReturnToFirstViewAppDelegate *)[[UIApplication sharedApplication]delegate];
//For example
//cell.image = appObj.selectedImage;
In any case if you dont like using AppDelegate Variables , there is one other method which You can use in case of Navigation Controllers :-
for eg. in "IConViewOne.m"
UITableViewCell* cell = [[[self.navigationController.viewControllers objectAtIndex:1] tableView] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]] ;
cell.imageView.image=[UIImage imageNamed:[NSString stringWithFormat:#"marco%d.png",button.tag]];
and then in "ViewWillAppear" of SecondView :-
[self.tableView reloadData];
Similarly for passing to RootViewController u can give:-
self.navigationController.topViewController.tableView
OR
[[self.navigationController.viewControllers objectAtIndex:0]tableView]
A great way to pass information from one object to another, without knowing who the recipient is (and there may be multiple objects interested in the information), is to post an NSNotification. It allows you to completely avoid direct knowledge of other objects.
Read Apple's document Notification Programming Topics and give it a try.

iphone : SDK disclosure button not response from first TableView to second detail TableView?

How can I pass the first tableview row data to second detail view row
I use
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
or
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
to show up disclosure button in each cells
it can ,I also add actions in
- (void)tableView:(UITableView *)tableViewaccessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
NSLog(#"disclosure button %# touched",indexPath.row);
}
But when I touch the disclosure button I got nothing shows up in console
Than I add actions in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// carry Alarm Name text into sub-table-view to look for detail time and text info
NSLog(#"Alarm Name = %#", [alarmName objectAtIndex:indexPath.row]);
NSLog(#"Index Path Raw# = %i", indexPath.row);
// Navigation logic may go here. Create and push another view controller.
AlarmDetailTableViewController *detailViewController = [[AlarmDetailTableViewController alloc] initWithNibName:#"AlarmTableViewController" bundle:[NSBundle mainBundle]];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
detailViewController = nil;
}
It can notified on console mode
But I think it always appear the same detail view when I touch any rows in First Level TableView
How to show a new detail view with data from Level one ?
for example
To make the tableView1.row0.text = detail view.title
and show other data under the title
if you need the code I can upload it
my boss said it's not big secret inside...
Thanks a lot
Perhaps the problem is with your:
- (void)tableView:(UITableView *)tableViewaccessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
which should be reading:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
Ok,if you tapped on accessory button than show another detail view
we need to add a detail view
First create a "new navigation based application",ex FirstView
right click on the class folder and choice "add new File" choice a new view you wanna display
ex I selected a new tableview named "DetailView"
than first go to the DetailView.m go give a section and row numbers
or declare the layout
than back to FirstView.h
add #import DetailView
go to FirstView.m
find this method - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
and use DetailView sub class to create a new view
add the codes like this
DetailView *detailView =[[DetailView alloc]init];
detailView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:detailView animated:YES];
you can add any view you want to display