push next view with didSelectRowAtIndexPath - cocoa-touch

I added this method didSelectRowAtIndexPath to go to the next view
no errors but i can't go to the next view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
detailhadith *detaihd = [[detailhadith alloc] initWithNibName:#"detailhadith" bundle:nil];
[self.navigationController pushViewController:detaihd animated:YES];
[detaihd release];
}

you can just add a subview like this: [self.view addSubview:nextView.view]; if you don't have a navigationController.

Related

UITableView non-using Navigation control

Can I not use Navigation control to switch my UIViewController?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
BATTrailsViewController *trailsController = [[BATTrailsViewController alloc] initWithStyle:UITableViewStylePlain];
trailsController.selectedRegion = [regions objectAtIndex:indexPath.row];
[[self navigationController] pushViewController:trailsController animated:YES];
}
Can I do this without using [[self navigationController] pushViewController:trailsController animated:YES];??
I want my UITableView selectrow to a new UIViewController without navigation.
try using
[self presentViewController:animated:completion];
Hope this helps.

Different ViewController called when TableView is Editing

I have a simple grouped table view that when a cell is selected it pushes a View controller. The navigation bar's left item puts the table view in "editing mode." In editing mode you can move and delete each cell as wanted. What I want is to be able to push a separate View controller when it is editing mode then when it is in normal mode.
This is where the View Controller is being pushed:
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...stuff that doesnt matter...
[[self navigationController] pushViewController:detailViewController animated:YES];
}
The BarButtonItems are being declared here:
[[self navigationItem] setLeftBarButtonItem:[self editButtonItem]];
This is where all the editing stuff is declared:
- (void)tableView:(UITableView *)atableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[atableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationFade];
}
}
- (void)tableView:(UITableView *)atableView
moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath
toIndexPath:(NSIndexPath *)destinationIndexPath
{
[[BNRItemStore sharedStore] moveItemAtIndex:[sourceIndexPath row]
toIndex:[destinationIndexPath row]];
}
When you push your view controller in the didSelectRowAtIndexPath, you can check if the tableview is in editing mode. If it is, you can push a different view controller.
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...stuff that doesnt matter...
if(aTableView.editing) // The tableview is in editing mode
[[self navigationController] pushViewController:otherViewController animated:YES];
else [[self navigationController] pushViewController:detailViewController animated:YES];
}
editing is a property that returns YES if the tableview is currently in editing mode.

Activate cell's accessory view (UISwitch) when didSelectRowAtIndexPath is called

Every cell of my tableView has a UISwitch as an accessoryView:
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
cell.accessoryView = mySwitch;
[mySwitch addTarget:self action:#selector(SwitchToggle:) forControlEvents:UIControlEventValueChanged];
Switch is toggled when the user taps it, but I also want it toggled when the didSelectRowAtIndexPath is called (when the user taps on that cell).
I tried this (but it doesn't work):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UISwitch *tempSwitch = (UISwitch *)[tableView cellForRowAtIndexPath:indexPath].accessoryView;
[tempSwitch addTarget:self action:#selector(SwitchToggle:) forControlEvents:UIControlEventValueChanged];
[tableView deselectRowAtIndexPath:indexPath animated:YES]; // cell selection fadeout animation
}
Thanks.
The code must look like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UISwitch *tempSwitch = (UISwitch *)[tableView cellForRowAtIndexPath:indexPath].accessoryView;
[tempSwitch setOn:!tempSwitch.on animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Remember that you also have to update your model.

passing data between firstviewcontroller's table view and secondviewcontroller of tabBarController

I want to do pass selected row text from first tab's table view to second tab's view label. I try this but it not work :S stringdir is a nsstring
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SecondViewController *detailViewController = [[SecondViewController alloc]initWithNibName:#"SecondView" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
detailViewController.stringdir= [ws2.CustomerName objectAtIndex:[indexPath row]];
NSLog(#"şişşşt %# ", detailViewController.stringdir);
[detailViewController release];
}
Move detailViewController.stringdir = ... before you push the view controller to nav controller stack.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SecondViewController *detailViewController = [[SecondViewController alloc]initWithNibName:#"SecondView" bundle:nil];
detailViewController.stringdir= [ws2.CustomerName objectAtIndex:[indexPath row]];
NSLog(#"şişşşt %# ", detailViewController.stringdir);
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}

Next screen on click of UITableCellView?

I have created UITableCellView in flipsideViewController of my Utility template. How to show next screen onclick of UITableCellView?
Create files for the view (YourViewController.h, YourViewController.m, YourViewController.xib). Set class of YourViewController.xib to YourViewController in interface builder. Connect view to view in interface builder, then in code
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *controller;
controller = [[UIViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}