Darkdrummer Darkdrummer - 2 months ago 22
Objective-C Question

View Controller for each Cell in Tableview

I'm very new on Objective C and i'm working on a project now.

I've created a Slide-Out-Menu, which is based on my own Database

Now I'm trying to get a Push-Seque from each Cell to a ViewController, but i have not really an idea how this works.

Here is my Code

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *numarray = [self getServerConnection];
for (NSDictionary *diction in numarray) {
NSDictionary *menuID = [diction objectForKey:@"id"];
NSString *num = [NSString stringWithFormat:@"%@",menuID];
intnum = [num intValue];
return intnum; }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

NSArray *namearray = [self getServerConnection];
for (NSDictionary *diction in namearray) {
name = [result valueForKey:@"name"];
identifier = [menuArray valueForKey:@"identifier"];

cell.textLabel.text = name [indexPath.row];


return cell; }


Suppose you have 4 Cells allocated in the side menu with following data.

  1. Home
  2. Profile
  3. Setting
  4. About Us

Each of these screen have segues from current view controller to the destination view controller with a identifier.

use a delegate method of UITableView class.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0){
        [self performSegueWithIdentifier:@"ProfileScreenSegueIdentifier" sender:self];
    }else if(indexPath.row == 1){
        [self performSegueWithIdentifier:@"HomeScreenSegueIdentifier" sender:self];
    }// So one...

Note: Please create push segues between each of your screens... Example. In above example there are three possibility of going to Home Screen

  1. From Profile to Home
  2. From Setting to Home
  3. From About Us to Home

So you need to create 3 segues from those screen to home with same identifier of segue. So there will be 12 segues in above example.