Navigating to a new view in iOS - iphone

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];
}

Related

iOS UITableViewController didSelectRowAtIndexPath not loading another UITableViewController

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];

How to Get the Next Class through each section of Uitableview?

In my Application i was using the different UIButtons as menue to Go Next class ,here is my Code
-(IBAction)GoToALevel
{
ALevel *obj = [[ALevel alloc] initWithNibName:#"ALevel" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
}
-(IBAction)GoToTLevel
{
TLevel *obj = [[TLevel alloc] initWithNibName:#"TLevel" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
}
-(IBAction)GoToNLevel
{
NLevel *obj = [[NLevel alloc] initWithNibName:#"NLevel" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
}
-(IBAction)GoToFLevel
{
FLevel *obj = [[FLevel alloc] initWithNibName:#"FLevel" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
}
Now i put all these catogories in UITableview.But can any one Guide me that how can get the Alevel when i click on first section of uitableview and so on .
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
here is problem how to go next class
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
switch (indexPath.row) {
case 0:
[self GoToALevel];
break;
case 1:
[self GoToTLevel];
break;
case 2:
[self GoToNLevel];
break;
case 3:
[self GoToFLevel];
break;
default:
break;
}
}
hope this helps. happy coding :)
You will have to write this code in DidSelectRowAtIndexPath(). i.e
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath.
Here you can specify the action according to the method. Before this use the
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
to specify the what happens at the index of each cell i.e. indexpath.row.

Moving to second viewController after selecting an item in the rootController

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.

navigation view doesn't work first click

I have a navigation view, when I click, I just show the row number.
In the mainView:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (read == nil) {
readNotice *aController = [[readNotice alloc]initWithNibName:#"readNotice" bundle:nil];
self.read = aController;
}
[read updateRowNumber:indexPath.row];
[[self navigationController] pushViewController:read animated:YES];
and in my readNotice class:
-(void)updateRowNumber:(int)theindex {
rowNumber = theindex + 1;
message.text = [NSString stringWithFormat:#"row %i was clicked", rowNumber];
NSLog(#"view did load row = %d", rowNumber);
}
readNotice.xib only contents a Label.
First time I click it shows "Label", but it works the following tries.
I suppose I need to initiliaze something that I missed, but I cant find it.
Thank you in advance
I m not able to understand why you made read variable .... ? use this ..
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
readNotice *aController = [[readNotice alloc]initWithNibName:#"readNotice" bundle:nil];
[self.navigationController pushViewController:aController animated:YES];
[aController updateRowNumber:indexPath.row];
}
may this will help you...
Use -
if (self.read == nil) {
readNotice *aController = [[readNotice alloc]initWithNibName:#"readNotice" bundle:nil];
self.read = aController;
}
--------
---------
[[self navigationController] pushViewController:self.read animated:YES];
Try this,
in tableview:didSelectRowAtIndex method,
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (read == nil) {
readNotice *aController = [[readNotice alloc]initWithNibName:#"readNotice" bundle:nil];
self.read = aController;
}
read.index = indexPath.row;
[[self navigationController] pushViewController:read animated:YES];
create a instance variable in readNotice as
#property(assign) int index;
#synthesize index;
In readNotice viewDidLoad method, you just call updateRowNumber
- (void)viewDidLoad
{
[super viewDidLoad];
[self updateRowNumber:index];
}
It will display the number as you expected

Uitablecell pushing into different nibs

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];
}
}