Views are getting overlapped in ios - iphone

This is my main screen where I added a table view.Now the problem arises when I click any of the tab ,my tab bar controller views is getting overlapped by the main view controller .
I need to resolve this error.
. If you didn't get my question correctly,please let me know.
Thanks
In Appdelegate I didn't write any code.
//MainViewController.m
- (void)viewDidLoad
{
getValuesFormDatabase=[[NSMutableArray alloc]init];
[self getAllRowsFromTableNamed];
[self getRefershToken];
}
//tab bar items
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
switch(item.tag){
case 1:
if (homeViewController == nil) {
self.homeViewController =
[[HomeViewController alloc] initWithNibName:homeViewController bundle:nil];
}
[self.view insertSubview:homeViewController.view belowSubview:myTabBar];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = homeViewController;
break;
case 2:
if (top25ViewController == nil)
{
self.top25ViewController =
[[Top25ViewController alloc] initWithNibName:top25ViewController bundle:nil];
}
[self.view insertSubview:top25ViewController.view belowSubview:myTabBar];
[ALToastView toastInView:self.view withText:#"Server is not responding"];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = top25ViewController;
break;
case 3:
if (myfavViewController == nil) {
self.myfavViewController =
[[MyFavViewController alloc] initWithNibName:myfavViewController bundle:nil];
}
[self.view insertSubview:myfavViewController.view belowSubview:myTabBar];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = myfavViewController;
break;
case 4:
if (moreViewController == nil) {
self.moreViewController =
[[MoreViewController alloc] initWithNibName:moreViewController bundle:nil];
}
[self.view insertSubview:moreViewController.view belowSubview:myTabBar];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = moreViewController;
break;
}
}
//table view
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [getValuesFormDatabase count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"Cell";
MainCell *cell = (MainCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell==nil) {
cell=[[MainCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.mainViewChannelName.text=[TableChannelNameArray objectAtIndex:indexPath.row];
cell.mainViewVideoName.text=[TableVideoNameArray objectAtIndex:indexPath.row];
return cell;
}

Related

How to grayout all tableview cells except selected one

I have a table view with custom cells ,there are uibuttons on custom cell ,if i select button except that cell remaining all cells should be grayouted or disabled is it possible.
// code in tableview class
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
NSLog(#"No OF rows:%d",[contents count]);
return [contents count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
static NSString *cellIdentifier = #"cell";
// Try to retrieve from the table view a now-unused cell with the given identifier.
cell = (uploadCustomCell *)[tableView dequeueReusableCellWithIdentifier:#"uploadCustomCell"];
if (cell == nil) {
NSLog(#"cell allocated");
// Use the default cell style.
cell = [[uploadCustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"uploadCustomCell"];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"uploadCustomCell"
owner:self options:nil];
cell = [nib objectAtIndex:0];
}
saveBtnCcell.hidden = YES;
cell.textNamefield.hidden = YES;
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell.defaultSwitch setEnabled:NO];
dictionaryContents = [contents objectAtIndex:indexPath.row];
NSLog(#"dict dict :%#",dictionaryContents);
//
cell
.nameLabelCell.text = [dictionaryContents valueForKey:#"VideoName"];
cell.userName.text = [dictionaryContents valueForKey:#"User"];
NSLog(#"Array Image:%#",arrayimage);
cell.thumbImg.image = [arrayimage objectAtIndex:indexPath.row];
NSLog(#"ARimage:%#,index%d",[arrayimage objectAtIndex:indexPath.row],indexPath.row);
NSString *defaultVideo = [dictionaryContents valueForKey:#"DefaultVideo"];
NSLog(#"Default Video:%#",defaultVideo);
if ([defaultVideo isEqual: #"1"]) {
// [cell.defaultSwitch setOn:YES animated:YES];
[defaultSwitche setOn:YES animated:YES];
}
else{
// [cell.defaultSwitch setOn:NO animated:YES];
[defaultSwitche setOn:NO animated:YES];
}
[cell.defaultSwitch addTarget:self action:#selector(setState:) forControlEvents:UIControlEventValueChanged];
VideoNameTextField.hidden = YES;
return cell;
}
// Code in customcell
#interface uploadCustomCell (){
UploadAllViewController *uploadAll;
}
#end
#implementation uploadCustomCell
#synthesize textNamefield;
#synthesize savebtn,edit,nameLabelCell,textLabel,uploadBTN;
#synthesize defaultSwitch;
//#synthesize uploadAll;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)dealloc {
[_userName release];
[_thumbImg release];
//[savebtn release];
[textNamefield release];
[nameLabelCell release];
[_test release];
[savebtn release];
[defaultSwitch release];
[uploadBTN release];
[super dealloc];
}
- (IBAction)editAction:(id)sender {
[uploadBTN setEnabled:NO];
uploadAll = [[UploadAllViewController alloc]init];
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:uploadAll.tabelView1];
NSIndexPath *indexPath = [uploadAll.tabelView1 indexPathForRowAtPoint:buttonPosition];
int no = indexPath.row;
NSLog(#"index path :%d",no);
[uploadAll didEditButtonPressed:self];
}
- (IBAction)saveBtnAction:(id)sender {
[uploadBTN setEnabled:YES];
[uploadAll didSaveButtonPressed:self];
}
when i select this editAction: except that cell remaining cells should be grayouted.
In your cellForRowAtIndexPath you have to account for the state of your table view, i.e. if one or zero cells are selected. Use that to change the appearance of your cell as you wish. In the example below I have assumed you are having a straight array without any sections, but the same principle would work with indexPaths as well. I use an int selectedRow set to -1 if there is no cell selected.
#define kNoCellSelected -1
// in cellForRowAtIndexPath:
if (self.selectedRow == kNoCellSelected) {
cell.backgroundView.backgroundColor = normalColor;
cell.userInteractionEnabled = YES;
}
else if (self.selectedRow != indexPath.row) {
cell.backgroundView.backgroundColor = disabledColor;
cell.userInteractionEnabled = NO;
}
Don't forget to set selectedRow in didSelectRowAtIndexPath: and in viewDidLoad.

Select certain row in one of the selections in a table view

I create a table with two sections. Each section has four cells.I want to push to a new view by navigation controller when a certain cell is pressed by user.
However there are two sections. I don't know how to distinguish the cell selected belongs to which section in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Please give me some tips. Thank you very much.
Here's my TableViewController.m
#import "TableViewController.h"
#import "LondonController.h"
#import "NewYorkViewController.h"
#import "ParisViewController.h"
#import "TokyoViewController.h"
#implementation TableViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)dealloc
{
[super dealloc];
[tableDataSource release];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStyleGrouped];
[table setDataSource:self];
[table setDelegate:self];
tableDataSource = [[NSMutableArray alloc]init];
NSMutableArray* sec1 = [[NSMutableArray alloc] init];
[sec1 addObject:#"London"];
[sec1 addObject:#"New York"];
[sec1 addObject:#"Paris"];
[sec1 addObject:#"Tokyo"];
[tableDataSource addObject:sec1];
[sec1 release];
NSMutableArray* sec2 = [[NSMutableArray alloc] init];
[sec2 addObject:#"Elton John"];
[sec2 addObject:#"Michael Jackson"];
[sec2 addObject:#"Little Prince"];
[sec2 addObject:#"SMAP"];
[tableDataSource addObject:sec2];
[sec2 release];
[self.view addSubview:table];
[table release];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if ( tableDataSource == nil )
return 1;
return [tableDataSource count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger bucketCount = -1;
NSObject *target_section;
if ( tableDataSource == nil )
return 0;
if( ( bucketCount = [tableDataSource count] ) < 1 || bucketCount <= section || (target_section = [tableDataSource objectAtIndex:section ]) == nil )
return 0;
return [ (NSMutableArray*)target_section count ];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: [NSString stringWithFormat:#"Cell %i",indexPath.section]];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:[NSString stringWithFormat:#"Cell %i",indexPath.section]] autorelease];
}
cell.textLabel.text = (NSString*)[ (NSMutableArray*)[tableDataSource objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if(section == 0)
{
return #"City";
}
else if(section == 1)
{
return #"Person";
}
else
{
return #"Nothing;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
LondonViewController *londonViewController = [[LondonViewController alloc] initWithNibName:#"LondonViewController" bundle:nil];
taipeiViewController.title = #"London Info";
[self.navigationController pushViewController:londonViewController animated:YES];
[londonViewController release];
}
else if (indexPath.row == 1)
{
NewYorkViewController *newYorkViewController = [[NewYorkViewController alloc] initWithNibName:#"NewYorkViewController" bundle:nil];
newYorkViewController.title = #"New York Info";
[self.navigationController pushViewController:newYorkViewController animated:YES];
[newYorkViewController release];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#end
In
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
you should check indexPath.section value to determine the section of the selected cell.
refer a NSIndexpath reference: http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSIndexPath_Class/Reference/Reference.html
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger section = indexPath.section;
NSUInteger row = indexPath.row;
if (section == 0)
{
LondonViewController *londonViewController = [[LondonViewController alloc] initWithNibName:#"LondonViewController" bundle:nil];
taipeiViewController.title = #"London Info";
[self.navigationController pushViewController:londonViewController animated:YES];
[londonViewController release];
}
else if (section == 1)
{
NewYorkViewController *newYorkViewController = [[NewYorkViewController alloc] initWithNibName:#"NewYorkViewController" bundle:nil];
newYorkViewController.title = #"New York Info";
[self.navigationController pushViewController:newYorkViewController animated:YES];
[newYorkViewController release];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

Calling a New View by selecting a UITableView Row Error

I am having some issues with pulling up specific ViewControllers depending on which row is selected in my UITableView. I have a table, which contains 3 sections, with 4 rows in each section.
When a row is selected I have it set to call a new view for each row, so 12 views in total to be called depending on which row is selected. The issue is, that only the first 4 views are called, when I tap row number 5, it displays a new view, but it pulls up the first view.
I have set my UITableView up using the following code;
carbData = [[NSArray alloc] initWithObjects:#"What Are Carbs?",#"Why Do I Need Carbs?",#"Simple Vs. Complex",#"Fun Five Facts",nil];
proteinData = [[NSArray alloc] initWithObjects:#"What is Protein?",#"Why Do I Need Protein?",#"Complete Vs. Incomplete",#"Fun Five Facts",nil];
fatData = [[NSArray alloc] initWithObjects:#"What Are Fats?",#"Why Do I Need Fats?",#"Saturated Vs. Unsaturated",#"Fun Five Facts",nil];
[self setTitle:#"Nutrition Table"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.carbData count];
return [self.proteinData count];
return [self.fatData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SimpleTableIdentifier] autorelease];
}
if(indexPath.section == 0)
cell.text = [carbData objectAtIndex:indexPath.row];
if(indexPath.section == 1)
cell.text = [proteinData objectAtIndex:indexPath.row];
if (indexPath.section == 2)
cell.text = [fatData objectAtIndex:indexPath.row];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
if(section == 0)
return #"Carbohydrates";
if (section ==1)
return #"Protein";
else if (section ==2)
return #"Fats";
}
I then use the following code to determine which view is to be called, when a certain row is selected;
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[carbData objectAtIndex:indexPath.row] isEqual:#"What Are Carbs?"]) {
CarbsView1 *controller = [[CarbsView1 alloc] initWithNibName:#"CarbsView1" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
if ([[carbData objectAtIndex:indexPath.row] isEqual:#"Why Do I Need Carbs?"]) {
CarbsView2 *controller = [[CarbsView2 alloc] initWithNibName:#"CarbsView2" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
if ([[carbData objectAtIndex:indexPath.row] isEqual:#"Simple Vs. Complex"]) {
CarbsView3 *controller = [[CarbsView3 alloc] initWithNibName:#"CarbsView3" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
if ([[carbData objectAtIndex:indexPath.row] isEqual:#"Fun Five Facts"]) {
CarbsView4 *controller = [[CarbsView4 alloc] initWithNibName:#"CarbsView4" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
if ([[proteinData objectAtIndex:indexPath.row] isEqual:#"What is Protein?"]) {
ProteinView1 *controller = [[CarbsView4 alloc] initWithNibName:#"ProteinView1" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
The app compiles and builds fine, everything works as i'd like it too, however when looking at the titles used, when I try and select "What is Protein?" is pulls up the view for "what are Carbs?" which is in the first if statement.
Any help would be massively appreciated
"What is Protein?" is in section 1, row 0. "What are Carbs?" is in section 0, row 0. Notice that your didSelectRowAtIndexPath method, you don't check the section number anywhere. So when you tap section 1, row 0, your first if statement returns true. I think you want something more like:
if (indexPath.section == 0) {
if(indexPath.row == 0) {
//present appropriate view controller
} else if (indexPath.row == 1) {
} else if (indexPath.row == 2) {
} ...
} else if (indexPath.section == 1) {
if (indexPath.row == 0) {
} else if (indexPath.row == 1) {
} ...
} ...

dismissModalViewControllerAnimated crashes app

I am new to iPhone development, so please pardon my ignorance.
I call a UIViewController from a UIViewController. The first UIViewController is a list of items, and the second is the detail for each of the items.
ListViewController (first UIViewController):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// initialize a AddViewController
selItem = indexPath.row;
selIndexPath = indexPath;
AddViewController *controller = [[AddViewController alloc] init];
// give controller the data to display
// show the AddViewController
[controller setData:[list objectAtIndex:indexPath.row]];
controller.delegate = self;
[self presentModalViewController:controller animated:YES];
[controller release]; // release the controller AddViewController
} // end method tableView:didSelectRowAtIndexPath:
In the 'AddViewController' I have a segment control as both the left and right button bars. On the left, I have 'Exit' and 'Delete'. On the right I have 'Add' and 'Save'. The outlets that the segment controls are linked to are:
AddViewController (second UIViewController):
- (IBAction)delExitSegment:sender
{
// The segmented control was clicked, handle it here
UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
switch (segmentedControl.selectedSegmentIndex) {
case 0: // Exit Button
[delegate addViewControllerDidExit:self];
break;
case 1: // Delete Button
[delegate addViewControllerDelItem:self];
break;
}
}
- (IBAction)segmentAction:sender
{
// The segmented control was clicked, handle it here
UISegmentedControl *segCtl = (UISegmentedControl *)sender;
switch (segCtl.selectedSegmentIndex) {
case 0: // Add Button
if (currentCell != nil)
[data setValue:currentCell.textField.text forKey:currentCell.label.text];
[delegate addViewControllerDidFinishAdding:self];
break;
case 1: // Save Button
[delegate addViewControllerUpdate:self];
break;
}
}
When I come back to my first view controller, I have:
ListViewController:
- (void)addViewControllerDidFinishAdding:(AddViewController *)controller
{
NSDictionary *item = [controller values];
if (item != nil)
{
[list addObject:item];
}
[self dismissModalViewControllerAnimated:YES];
[list writeToFile:itemFilePath atomically:NO];
[self calcTotal];
[self.tableView reloadData];
}
- (void)addViewControllerUpdate:(AddViewController *)controller
{
NSDictionary *item = [controller values];
if (item != nil)
{
[list replaceObjectAtIndex:selItem withObject:item];
}
[self dismissModalViewControllerAnimated:YES];
[list writeToFile:itemFilePath atomically:NO];
[self calcTotal];
[self.tableView reloadData];
}
- (void)addViewControllerDidExit:(AddViewController *)controller
{
[self dismissModalViewControllerAnimated:YES];
[self.tableView reloadData];
}
- (void)addViewControllerDelItem:(AddViewController *)controller
{
NSDictionary *item = [controller values];
if (item != nil)
{
[list removeObjectAtIndex:selItem];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:selIndexPath] withRowAnimation:UITableViewRowAnimationFade];
[list writeToFile:itemFilePath atomically:NO];
}
[self dismissModalViewControllerAnimated:YES];
[self.tableView reloadData];
}
If I exit or delete an item from AddViewController, I have no problems. When I try and add or save, then my application will crash. The debugger crashes at dismissModalViewControllerAnimated. I can't see what's different between the two segment controls.
Any ideas what I may have wrong?
I just discovered that neither the left or right buttons work when I attempt to edit a cell. The editing cell in AddViewController is as follows:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = #"EditableCell";
EditableCell *cell = (EditableCell *)[table dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[EditableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
NSString *key = [fields objectAtIndex:indexPath.row + indexPath.section * 3];
[cell setLabelText:key];
cell.textField.text = [data valueForKey:key];
if (indexPath.section == 0 && (indexPath.row == 1 || indexPath.row == 3))
cell.textField.keyboardType = UIKeyboardTypeNumberPad;
if (indexPath.section == 1)
cell.textField.keyboardType = UIKeyboardTypeNumberPad;
cell.editing = NO;
cell.delegate = self;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
Here is the problem:
[self dismissModalViewControllerAnimated:YES];
[self.tableView reloadData];
When you dismiss the view the value of self become unknown, accessing the tableview will definitely crash.
If you want to refresh the tableView just use [self.tableView reloadData] and don't dismiss the view.

How can you push a new view with a grouped table?

Ive been trying to push a new view when a cell is tapped but absolutely nothing happens. I figured grouped style pushed the same as plain. Here is my code:
-(void)viewDidLoad {
[super viewDidLoad];
contactArray = [[NSArray alloc] initWithObjects:#"iPhone",#"iPod",#"MacBook",#"MacBook Pro",nil];
shareArray = [[NSArray alloc] initWithObjects:#"Flex",#"AIR",#"PhotoShop",#"Flash",nil];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
// Customize the number of rows in the table view.
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0)
return [contactArray count];
else
return [shareArray count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
if(section == 0){
return #"Contact";
}else{
return #"Share";
}
}
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
if(section == 0){
return #"Footer for Apple Products";
}else{
return #"Footer for Adobe Softwares";
}
}
// Customize the appearance of table view cells.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
if(indexPath.section == 0){
cell.text = [contactArray objectAtIndex:indexPath.row];
}else{
cell.text = [shareArray objectAtIndex:indexPath.row];
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//NextViewController *nextController = [[NextViewController alloc] initWithNibName:#"NextView" bundle:nil];
//[self.navigationController pushViewController:nextController animated:YES];
if([contactArray objectAtIndex:indexPath.row] == #"iPhone"){
LandscapeHydrogen *abo = [[LandscapeHydrogen alloc] initWithNibName:#"LandscapeHydrogen" bundle:nil];
[self.navigationController pushViewController:abo animated:NO];
[abo release];
}
}
Any help is appreciated.
You could put a breakpoint at the didSelectRowAtIndexPath to see if the if statement is true.
Try changing
if([contactArray objectAtIndex:indexPath.row] == #"iPhone"){
to
if([[contactArray objectAtIndex:indexPath.row] isEqualToString:#"iPhone"]){
YourNextViewController * nextViewController = [[YourNextViewController alloc] initWithNibName: #"YourNextViewController" bundle: nil];
switch (indexPath.section) {
case 0:
nextViewController.title = [_contactArray objectAtIndex: [indexPath row]];
break;
case 1:
nextViewController.title = [_shareArray objectAtIndex: [indexPath row]];
break;
default:
break;
}
[[self navigationController] pushViewController:nextViewController animated:YES];
}
Solved with
else if (indexPath.section == 1 & indexPath.row == 0){
FaceBook *nextController = [[FaceBook alloc] initWithNibName:#"FaceBook" bundle:nil];
[self.navigationController pushViewController:nextController animated:YES];