TabelViewController with story board in ios5 - ios

I have started working with story board ,a new feature in iOS 5,so I started with a tabbed application,then I added a table view controller and filled the cells with some dummy data,now,the table has 4 cells,now on click of each cell,I want to open a newViewController,which will be diffrent for each cell,
So previously,I used to code this way
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if(indexPath.row == 0)
{
FirstViewController *settingsView =[[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
[self.navigationController pushViewController:settingsView animated:YES];
}
if(indexPath.row == 1)
{
SecondViewController *settingsView =[[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:settingsView animated:YES];
}
if(indexPath.row == 2)
{
ThirdViewController *settingsView =[[ThirdViewController alloc]initWithNibName:#"ThirdViewController" bundle:nil];
[self.navigationController pushViewController:settingsView animated:YES];
}
}
But know,how shall I do it..please help me out
Thanks & Regards
Ranjit

Maybe this tutorial would help you?
http://kurrytran.blogspot.com/2011/10/ios-5-storyboard-uitableview-tutorial.html
As I see this (performSegueWithIdentifier:sender:) should be the method to perform a new viewcontroller from the storyboard
https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/performSegueWithIdentifier:sender:

Related

How can I push view controller with storyboard identifier using LGSideMenuController?

I have to push a detail view controller when I tap on a tableview cell using with storyboard identifier. I have already designed the view controller. Now i have to navigate to the designed screen by tapping table view cell in the left menu. I am using LGSideMenuController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
if (indexPath.row == 0) {
ProfileViewController *profileVC = (ProfileViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:PCProfileVC];
[self.leftMenuVC navigateToViewController:#"profileVC"];
}}
-(void)navigateToViewController:(UIViewController*)viewController{
[(UINavigationController *)[self sideMenuController].rootViewController pushViewController:viewController animated:YES];
[[self sideMenuController] hideLeftViewAnimated:YES completionHandler:nil];}
Please help me to do. Thanks
Why are you pushing viewController in rootViewController.
If this code snippet is written in your ViewController.m, then try replacing,
[(UINavigationController *)[self sideMenuController].rootViewController pushViewController:viewController animated:YES];
with
[[self sideMenuController].rootViewController.navigationController pushViewController:viewController animated:YES];
If your identifier PCProfileVC is correct, then this code should work.
Kindly see this link for information on pushing ViewController in UINavigationController.
Try this code :
YourViewControllerClass *viewController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:#"ViewController"];
// instanciate your viewcontroller
[(UINavigationController *)[self sideMenuController].rootViewController pushViewController:viewController animated:YES]; //push your viewcontroller
[[self sideMenuController] hideRightViewAnimated:YES completionHandler:nil]; //hide the menu

Cant navigate to other Viewcontrollers from a commonViewController's tableview click

I have a commonViewController to pop up on other viewcontrollers and the commonViewController has a view and a tableview inside it and also some other components. I have populated that view successfully on other viewcontroller pages, but the problem is; when iam trying to navigate to some other viewcontroller pages while iam clicking the rows in commonViewController's tableview.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 1)
{
EditProfileViewController *nextViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"EPVController"];
[self.navigationController pushViewController:nextViewController animated:YES];
}
}
I have tried both presentViewController and pushViewController but it is not navigating anywhere. What is the issue. Please help me.
Get reference to your storyboard and load viewcontroller using identifier:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"YourStoryboardName" bundle:nil];
EditProfileViewController *nextViewController = [storyboard instantiateViewControllerWithIdentifier:#"EPVController"];
[self.navigationController pushViewController:nextViewController animated:YES];

Push a view when click the tableviewcell

I want to push a view when I click the cell of my tableview.The code is as followed:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.tag == todoTableViewTag) {
NSLog(#"aa");
ViewControlleraaa* testvc = [[ViewControlleraaa alloc] initWithNibName:#"ViewControlleraaa" bundle:nil];
[self.navigationController pushViewController:testvc animated:YES];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
but it does not work at all.
I have
ViewControlleraaa.h ViewControlleraaa.m and ViewControlleraaa.xib
but I did nothing except creating them.
So where is the problem?
Create a 'generic' segue from your table view controller to ViewControlleraaa and use 'performSegueWithIdentifier'. If that approach is not possible to execute then you may want to try 'presentViewController' instead.
Try creating a manual segue from your table view controller to ViewControlleraaa. Then, as the answerer above me said, you can use performSegueWithIdentifier to call the segue. If you should ever need the table view controller to push any data to the ViewControlleraaa, you can do so using the "prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender" method. The destinationViewController property of "segue" is ViewControlleraaa.
Here's a link to a YouTube video, in case you need any additional help: https://www.youtube.com/watch?v=XApYtAlRDVE
Check self.navigationController is not nil then surly it will work fine.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ViewController *vc = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
}

Event clicked in UITableView

I have a problem when clicked a row in a UITableView
I used this method didSelectRowAtIndexPath to catch when the user clicks on a row, but doesn't work normally.
the user must press and hold the row to execute the action but do not want it to be so.
Any idea what may be happening?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
Refunds *current = [refunds_view objectAtIndex:indexPath.row];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
DetailRefundsViewController *myVC = (DetailRefundsViewController *)[storyboard instantiateViewControllerWithIdentifier:#"DetailRefundsViewController"];
[self presentViewController:myVC animated:YES completion:nil];
}
Thanks.
Best Regards.
In my case, your code is instantly work, just modify class name and Storyboard Identifier.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
LJWDetailViewController *myVC = (LJWDetailViewController *)[storyboard instantiateViewControllerWithIdentifier:#"LJWDetailViewController"];
[self presentViewController:myVC animated:YES completion:nil];
}
I think, some of your codes are block this didSelectRowAtIndexPath: Method.
find out which controls are block this method
and set those control's delaysContentTouches Property by NO like this.
_imageScroll.delaysContentTouches = NO;
Sorry for Poor English :<
If you're using StoryBoards, then I think you're better off using a push segue directly from the TableViewCell to the ViewController you want in the Interface Builder (control click and drag from the TableViewCell to the ViewController). Make sure to give the segue a name (in my case below "showDetail"). Then implement the code below:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"]) {
[[segue destinationViewController] setDetailItem:object];
}
}

How to load entirely different ViewController in a Master-Detail app?

I have a Master-Detail app and I want to load a new view on the click of rows in Master. If I select row-1, the view is different, and on selection of a different row, new view is presented in Detail portion. How can I achieve this thing?
I am doing something like this. The issue is - If I select any of these 2 rows for the first time, the view actually changes. But again when I click on the other row, it does not change.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
TwitterTweetViewController *detailView=(TwitterTweetViewController *)[storyboard instantiateViewControllerWithIdentifier:#"TwitterDetailView"];
self.splitViewController.mainViewController = detailView;
[self.splitViewController.mainViewController viewDidLoad];
[self.splitViewController viewDidLoad];
}
if(indexPath.row == 1)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
TwitterDetailViewController *detailView=(TwitterDetailViewController *)[storyboard instantiateViewControllerWithIdentifier:#"TwitterDetailView"];
self.splitViewController.mainViewController = detailView;
[self.splitViewController.mainViewController viewDidLoad];
[self.splitViewController viewDidLoad];
}
}
What should I do in order to change the view on selecting these rows?
There is a great method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Use it. It is called right after the click has been made on a cell. You can put some check in there. Short example:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
SomeViewController *svc = [[SomeViewController alloc]initWithNibName:#"SomeViewController" bundle:nil];
[self.navigationController pushViewController:svc];
} else if (indexPath.row > 0 && indexPath.row < 5) {
SomeOtherViewController *sovc = [[SomeOtherViewController alloc]initWithNibName:#"SomeOtherViewController" bundle:nil];
[self.navigationController pushViewController:sovc];
} else {
AnotherViewController *avc = [[AnotherViewController alloc]initWithNibName:#"AnotherViewController" bundle:nil];
[self.navigationController pushViewController:avc];
}
//some other code if needed
}
Hope it helps
You can create an enum of your view controllers as :-
enum MyViewControllers
{
viewcontroller1
viewcontroller2
viewcontroller3
}
The constatns in enum would correspond to your viewcontrollers for each indexPAth.
and then in the delegate method of UITAbleVIew didSelectRowAtIndexPath: , use switch case :-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
switch(indexPath.row)
{
case 1:
Load view1
break;
case 2:
Load view2
break;
case 3:
Load view3
break; .
.
so on.
}
}
Or in case of different NavigationControllers (as in iPad )you will have to pass data using delegates and protocol.Define the protocol in rootViewController and then set its delegate in the detail(Where you want to push the viewcontroller)
somethinglike :-
#protocol SendSelectedINdexDelegate
{
#required
-(void)sendTheIndex:(NSNumber)number.
#end
in interface
id <SendSelectedINdexDelegate> delegateSend
set its property:-
#property (nonatomic) id delegateSend;
in .m
#synthesize delegateSend
and in didSelectRowAtIndexPath:-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
[self delegate]sendTheIndex:indexPath.row];
}
At the receiving controller
conform to protocol
and set
rootview.delegateSend=self;
and implement the method of protocol;
-(void)sendTheIndex:(NSNumber)number
{
//nsnumber is your index perform operation based on this.
}
Take care that if you are using ARC,it forbids synth of a property with unspecified ownership attribute( in .m #synthesize delegateSend).

Resources