Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell and UITableView (did select a row) navigation to otherViewcontroller

Tags:

iphone

I hav a UITableViewCell and UITableView in a single view.Clicking on particular row of UITableView ,It navigates to anotherViewController.But I am not able to navigate to otherViewController on clicking UITableViewCell.How can i do this??

For UITableView I am using this code:

-(void)pushView1:(id)sender{
    if(edController == nil)
    edController = [[EditableDetailCell alloc] initWithNibName:@"EditableDetailCell" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:edController animated:YES];
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UITableViewCell *tbcel;
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    tbcel.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    tbcel.layer.cornerRadius = 15;
    tbcel.text = aBook.Name;
    switch(indexPath.section)
    {
         case 0:
            cell.text = aBook.Address;
            break;
        case 1:
            cell.text = aBook.Phone;
            break;
        case 2:
            cell.text = aBook.Purchase;
    }
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(edController == nil)
    edController = [[EditableDetailCell alloc] initWithNibName:@"EditableDetailCell" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:edController animated:YES];
}

enter image description here

What should I do for UITableViewCell??

ist is tableviewcell and below it in block is tableview

like image 651
Ketan Shinde Avatar asked Nov 06 '22 00:11

Ketan Shinde


2 Answers

Edit:

what you want to push is not a UITableViewCell

It's another View.

You can say

YourCustomView *view = [[YourCustomView alloc] init];
[self.navigationController pushViewController:view animated:Yes];

but I never see any code passing to another cell.

A cell is used to customize the look of you UITableView.

Add:

I think the if statement is not useful here.

Do you mean

if(edController == nil){
    edController = [[EditableDetailCell alloc] initWithnibName:@"EditableDetailCell" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:edController animated:YES];
}

or an empty view is going to be passed any way.

like image 186
Xiao Avatar answered Nov 12 '22 18:11

Xiao


 (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
 {
    NSLog(“Selected Row %d”, indexPath.row);
    YourNextViewController *objVC = (YourNextViewController *)[storyboard instantiateViewControllerWithIdentifier:@"ViewControllerIdentifier"];
   [self presentViewController: objVC animated:YES completion:nil];
 }
like image 31
Yash Joshi Avatar answered Nov 12 '22 18:11

Yash Joshi