I have two classes one is viewcontroller that include viewcontroller.h ,viewcontroller.m, viewcontroller.xib. Second is detailviewcontroller that include detailviewcontroller.h, detailviewcontroller.m , detailviewcontroller1.xib , detailviewcontroller2.xib , detailviewcontroller3.xib.
I use splitviewcontroller left side is viewcontroller.xib with tableview and has 3 option.
when I click on first option it show detailviewcontroller1.xib // for registration page
when I click on second option it show detailviewcontroller2.xib// view all data in table from database
when I click on third option it show detailviewcontroller3.xib // display chart related to table data ...
problem is how can I manage this three nib file ?????
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
//
}
else if (indexPath.row == 1)
{
}
else if (indexPath.row == 2)
{
}
}
please answer me I didn't know because I am new in iOS, I started to learn iOS programming.
please answer me .......
Related
Right now, my initial view just opens up as whatever view controller is connected to the 0th row index for my left menu. This happens to be the home page for the app. How can I uncouple this from the table/menu? I want to create a home page that will load initially, but I do not want to use up a row in my menu. I still want to be able to pull up the menu to go to other parts of the app though and then have a separate home button. I'm using the storyboard version of AMSlideMenu. I've tried rearranging the home view controller, so that it comes before the menu in my storyboard to no avail. The app just gets a thread error and crashes. Can someone please tell me how to do this properly?
You can override the following methods in MainVC.m
(NSIndexPath *)initialIndexPathForLeftMenu;
(NSIndexPath *)initialIndexPathForRightMenu;
AMSlideMenuMainViewController.m
This will change from 0 to any custom number you provide
- (NSIndexPath *)initialIndexPathForRightMenu
{
return [NSIndexPath indexPathForRow:<50> inSection:0];
}
RightMenuTVC.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UINavigationController *nvc;
UIViewController *rootVC;
switch (indexPath.row) {
case <50> :
{
... }
I am currently developing an app for iPhone and i have a spent time looking at how to select multiple rows in a table view however the answers i found did not include groups. I have a table as seen below with two groups one for client selection and the other for navigation links i would like to display the selected item for both groups rather than the entire table but i have had no luck finding any answers for this.
i understand you check can what section the row is in but i am not sure how to implement this. Any suggestions would be greatly appreciated. Additionally i do know how to select rows by changing the cell style depending on if it has been selected or not but its doing this for two groups im stuck on. Again thank you for any help.
This is the code to allow for multiple selection:
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.allowsMultipleSelection = YES;
}
Perhaps you are looking for something like this to execute code based on which section the selection is in:
#define CLIENT_SECTION 0
#define MENU_SECTION 1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == CLIENT_SECTION) {
// execute code
} else if (indexPath.section == MENU_SECTION) {
// execute code
}
}
-(void)viewDidLoad{
[myTable setMultipleTouchEnabled:YES];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section == 0)
{
[[myTable cellForRowAtIndexPath:indexPath.row] setAccessoryType:UITableViewCellAccessoryCheckmark];
}
else
{
[[myTable cellForRowAtIndexPath:indexPath.row] setAccessoryType:UITableViewCellAccessoryCheckmark];
}
}
Currently I have an array of objects right now
- (void)viewDidLoad
{
[super viewDidLoad];
self.webSites = [NSMutableArray arrayWithObjects:#"Website", #"iOS", #"Android", nil];
}
I am trying to access the one at index:0 which should be Website with the following code to perform a segue to another table view controller where there will be categories to select from.
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
[self performSegueWithIdentifier:#"viewCategories" sender:nil];
}
}
Every time I run the app I click on Website and nothing happens, but when I click on iOS the segue performs. Any answer as to why I'm running into this problem?
You are using wrong method.
didDeselectRowAtIndexPath // Used for deselecting the cell row
should be
didSelectRowAtIndexPath // Used for selecting the cell row
I want to navigate from a tableviewcell to another view by the cell's path.
I am using the following code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath == 0) {
[self performSegueWithIdentifier:#"segueToKnutene" sender:self];
}
As you might understand, this did not work.
Keep in mind that i am fairly new to xcode and objective-c.
In my head what this does is performing a segue to another view if the top cell in my tableview is pressed/released. And this is also what i want to do.
An NSIndexPath consists of a row and a section.
So you probably want to use
if (indexPath.section == 0 && indexPath.row == 0)
I'm new to iPhone dev and wanted to get advice on the general design pattern / guide for putting a certain kind of app together.
I'm trying to build a TabBar type application. One of the tabs needs to display a TableView and selecting a cell from within the table view will do something else - maybe show another table view or a web page. I need a Navigation Bar to be able to take me back from the table view/web page.
The approach I've taken so far is to:
Create an app based around UITabBarController as the rootcontroller
i.e.
#interface MyAppDelegate : NSObject <UIApplicationDelegate>
{
IBOutlet UIWindow *window;
IBOutlet UITabBarController *rootController;
}
Create a load of UIViewController derived classes and associated NIBs and wire everything up in IB so when I run the app I get the basic tabs working.
I then take the UIViewController derived class and modify it to the following:
#interface MyViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
{
}
and I add the delegate methods to the implementation of MyViewController
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (indexPath.row == 0)
{
cell.textLabel.text = #"Mummy";
}
else
{
cell.textLabel.text = #"Daddy";
}
return cell;
}
Go back to IB , open MyViewController.xib and drop a UITableView onto it. Set the Files Owner to be MyViewController and then set the delegate and datasource of the UITableView to be MyViewController.
If I run the app now, I get the table view appearing with mummy and daddy working nicely. So far so good.
The question is how do I go about incorporating a Navigation Bar into my current code for when I implement:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath()
{
// get row selected
NSUInteger row = [indexPath row];
if (row == 0)
{
// Show another table
}
else if (row == 1)
{
// Show a web view
}
}
Do I drop a NavigationBar UI control onto MyControllerView.xib ? Should I create it programmatically? Should I be using a UINavigationController somewhere ? I've tried dropping a NavigationBar onto my MyControllerView.xib in IB but its not shown when I run the app, only the TableView is displayed.
http://miketeo.net/wp/index.php/2008/08/31/simple-iphone-tutorial-part-3.html
this code was very helpfull for me. You can download and use this code..