Hello I am trying to push different nibfiles into view
When you click On the uitablecell it corresponds to.
I have no Idea where to start.
Read UITableView class and navigation based app and see this code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//and code like this
if(indexPath.row==0)
{
FirstController *objFirstController=[[[FirstController alloc] initWithNibName:#"FirstView" bundle:nil] autorelease];
[self.navigationController pushViewController:objFirstController animated:YES];
}
else
{
SecondController *objSecondController=[[[SecondController alloc] initWithNibName:#"SecondView" bundle:nil] autorelease];
[self.navigationController pushViewController:objSecondController animated:YES];
}
}
Related
I've been trying to push a uiwebview from a tableview to no avail. This is the code I have right now and whenever I click the cell, it would crash and show me the error.
Courses.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([[array objectAtIndex:indexPath.row] isEqual:#"GolfClub"])
{
Blue *changi = [[Blue alloc] initWithNibName:#"Golf Club" bundle:nil];
[self.navigationController pushViewController:changi animated:YES];
[changi release];
}
else if ([[array objectAtIndex:indexPath.row] isEqual:#"ExecutiveGolfCourse"])
{
ExecutiveGolfCourse *egc = [[ExecutiveGolfCourse alloc] initWithNibName:#"Executive Golf Course" bundle:nil];
[self.navigationController pushViewController:egc animated:YES];
[egc release];
}
newsClicked.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:newsClicked animated:YES];
}
initWithNibName is not meant for the title of your ViewController
nib name is actually the name of the .xib file that is associated with that ViewController
I have a UITableViewController working just fine with all the content when I tap on one of the cells didSelectRowAtIndexPath is being call but doesn't go to the next UITableViewController. Here is my code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ViewHeadersController *detailViewController = [[ViewHeadersController alloc] initWithNibName:#"ViewHeadersController" bundle:nil];
NSArray *resultsData = [_response objectForKey:#"results"];
detailViewController.urlHeaders = [[resultsData objectAtIndex:indexPath.row] objectForKey:#"url"];
[self.navigationController pushViewController:detailViewController animated:YES];
}
I know didSelectRowAtIndexPath is responding because I see the output of the NSLog.
Any of you knows what is going on or why the uitablevicontroller is not switching to the next UITableViewController?
I'll really appreciate your help
I change the line where is navegationController:
ViewHeadersController *detailViewController = [[ViewHeadersController alloc] initWithNibName:#"ViewHeadersController" bundle:nil];
detailViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
NSArray *resultsData = [_response objectForKey:#"results"];
detailViewController.urlHeaders = [[resultsData objectAtIndex:indexPath.row] objectForKey:#"url"];
[self presentViewController:detailViewController animated:YES completion:nil];
I created app that have tableView with a viewController, what it should do is after selecting an item move to the second viewController and open it with passed data. I am implementing the next thing in the RootTableView:
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selecteditem = [listOfItems objectAtIndex:indexPath.row];
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:[NSBundle mainBundle]];
dvController.selectedItem = selectedItem;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
this code should work basicly but after I am selecting an item its been selected(blue colored) and that it, its stays with the selected blue color and nothing happened...after i selecting another row the same thing happens, what's wrong with my code?
You simply need to disable the selection styling when adding cells to your table:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
just put following code into your code
[self.tableView deselectRowAtIndexPath:
[self.tableView indexPathForSelectedRow] animated:YES];
like i.e
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selecteditem = [listOfItems objectAtIndex:indexPath.row];
// implement my code
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:[NSBundle mainBundle]];
dvController.selectedItem = selectedItem;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
I think you should check the navigationController. It might be not initialized.
You must have a UINavigationController to push any controller inside.
In my iPad application I added UISearchBar programmatically.
When I click on the searchBar, a table containing data appears. When I tap on the row in table, it should navigate to new view
for example:
when I tap on "reliance" it should show a new view. Any suggestions on how I can accomplish this?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ContentController *detailview = [[ContentController alloc] initWithNibName:#"ContentController" bundle:nil];
detailview.detailString = [NSString stringWithFormat:#"%d",indexPath.row];
[self.view addSubView:detailView];
[detailview release];
}
so I added the code above. Do I need to do anything else?
Implement the UITableViewDelegate method didSelectRowAtIndexPath and push your new view onto the navigation stack.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Some code
// Initialize your new view here
[self.navigationController pushViewContoller:yourViewController animated:YES];
}
Try -
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ContentController *detailview = [[ContentController alloc] initWithNibName:#"ContentController" bundle:nil];
detailview.detailString = [NSString stringWithFormat:#"%d",indexPath.row];
// [self.navigationController pushViewController:detailview animated:YES];
[self.view addSubView:detailView];
[detailview release];
}
I have two different sections in a tableview. I want to navigate to two different viewcontrollers on click of rows in different sections. I know that this can be accomplished in didSelectRowAtIndexPath() method but i am thinking on how to differentiate the click of rows in different sections.Can u please help me if this can be implemented?
You can use a switch statement to determine the section of the UITableView.
Example:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch ( indexPath.section )
{
case 0:
{
FirstViewController * first = [[FirstViewController alloc] init];
[self.navigationController pushViewController: first animated: YES];
}
break;
case 1:
{
SecondViewController * second = [[SecondViewController alloc] init];
[self.navigationController pushViewController: second animated: YES];
}
break;
}
}
Do Something like this in you didSelectRowtIndexPath :-
if (indexPath.section==0 && indexPath.row==0) {
//Do Something
}
Or you can use switch case.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *viewController;
switch (indexPath.section) {
case 0:
viewController = [[[FirstExampleViewController alloc] init] autorelease];
break;
case 1:
viewController = [[[SecondExampleViewController alloc] init] autorelease];
break;
case 2:
viewController = [[[ThirdExampleViewController alloc] init] autorelease];
break;
default:
viewController = [[[UIViewController alloc] init] autorelease];
}
[self.navigationController pushViewController:viewController animated:YES];
}