Skip to main content
Post Closed as "Not suitable for this site" by 200_success
Post Reopened by 200_success
Post Closed as "Not suitable for this site" by nhgrif, Simon Forsberg, Alex L, syb0rg, 200_success
deleted 110 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Passing Row Index of TableViewCell [ custom](custom) to another view controller

I have been trying to achieve the below requirement. I could ablerequirements to get itthem working.

But want to make sure if i am Am I doing in ait the right way  ?

  1. We have a table with customised Cell. [ say (say: firstViewController]firstViewController)

  2. Customised Cell has a button  , click event in this button, carries rowand carries row index value to another view controller, and in. In this view controller iI will use this row index to accessaccess the data model from Firstfirst view controller.

Annotation: EachEach row has values associated with unique Dictionary value in Array based on row Index.

Pseudo Code:[ pasted (pasted only necessary code ])

FirstViewController.mFirstViewController.m

In the above code I set the iRecordIndexiRecordIndex to IndexPath.rowIndexPath.row

StudentCell.hStudentCell.h

StudentCell.mStudentCell.m

NextViewController.hNextViewController.h

NextViewController.mNextViewController.m

 - (id)initWithRecIndex:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  Index:(NSInteger )iRecIndex
{
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.iRecordIndex = iRecIndex;
    }

    return self;
}



 

-(void) viewWillAppear:(BOOL)animated
{
    //Get FistViewController.   say  ==> fvc.

    NSMutableArray *mRec = [fvc MasterRecords];
    NSMutableDictionary *mDict = [mRec objectAtIndex:self.iRecordIndex];
    
    NSLog (@" value1 is %@ ", [mDict valueForKey:@"value1"]);
    NSLog (@" value2 is %@ ", [mDict valueForKey:@"value2"]);
    
   // Using value1, and value2 to display MKMapView.


    
}

I am afraid if it is aIs this the right approach?., or where i couldshould I improve it?

Passing Row Index of TableViewCell [ custom] to another view controller

I have been trying to achieve the below requirement. I could able to get it working.

But want to make sure if i am doing in a right way  ?

  1. We have a table with customised Cell. [ say: firstViewController]

  2. Customised Cell has a button  , click event in this button, carries row index value to another view controller, and in this view controller i will use this row index to access data model from First view controller.

Annotation: Each row has values associated with unique Dictionary value in Array based on row Index.

Pseudo Code:[ pasted only necessary code ]

FirstViewController.m

In the above code I set the iRecordIndex to IndexPath.row

StudentCell.h

StudentCell.m

NextViewController.h

NextViewController.m

 - (id)initWithRecIndex:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  Index:(NSInteger )iRecIndex
{
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.iRecordIndex = iRecIndex;
    }

    return self;
}



 

-(void) viewWillAppear:(BOOL)animated
{
    //Get FistViewController.   say  ==> fvc.

    NSMutableArray *mRec = [fvc MasterRecords];
    NSMutableDictionary *mDict = [mRec objectAtIndex:self.iRecordIndex];
    
    NSLog (@" value1 is %@ ", [mDict valueForKey:@"value1"]);
    NSLog (@" value2 is %@ ", [mDict valueForKey:@"value2"]);
    
   // Using value1, and value2 to display MKMapView.


    
}

I am afraid if it is a right approach?. or where i could improve it?

Passing Row Index of TableViewCell (custom) to another view controller

I have been trying to achieve the below requirements to get them working. Am I doing it the right way?

  1. We have a table with customised Cell (say: firstViewController)

  2. Customised Cell has a button, click event in this button, and carries row index value to another view controller. In this view controller I will use this row index to access the data model from first view controller.

Annotation: Each row has values associated with unique Dictionary value in Array based on row Index.

Pseudo Code: (pasted only necessary code)

FirstViewController.m

In the above code I set the iRecordIndex to IndexPath.row

StudentCell.h

StudentCell.m

NextViewController.h

NextViewController.m

 - (id)initWithRecIndex:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  Index:(NSInteger )iRecIndex
{
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.iRecordIndex = iRecIndex;
    }

    return self;
}

-(void) viewWillAppear:(BOOL)animated
{
    //Get FistViewController.   say  ==> fvc.

    NSMutableArray *mRec = [fvc MasterRecords];
    NSMutableDictionary *mDict = [mRec objectAtIndex:self.iRecordIndex];
    
    NSLog (@" value1 is %@ ", [mDict valueForKey:@"value1"]);
    NSLog (@" value2 is %@ ", [mDict valueForKey:@"value2"]);
    
   // Using value1, and value2 to display MKMapView.
}

Is this the right approach, or should I improve it?

Source Link
Whoami
  • 119
  • 1
  • 1
  • 3

Passing Row Index of TableViewCell [ custom] to another view controller

I have been trying to achieve the below requirement. I could able to get it working.

But want to make sure if i am doing in a right way ?

  1. We have a table with customised Cell. [ say: firstViewController]

  2. Customised Cell has a button , click event in this button, carries row index value to another view controller, and in this view controller i will use this row index to access data model from First view controller.

Annotation: Each row has values associated with unique Dictionary value in Array based on row Index.

Pseudo Code:[ pasted only necessary code ]

FirstViewController.h

 @interface firstViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>


 @property NSMutableArray *MasterRecords;   //  Each element in Array is dictionary. 
 @property (weak, nonatomic) IBOutlet UITableView *tblMasterTable;
 @end

FirstViewController.m

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *columnIdfer = @"items";
    StudentCell *cell = (StudentCell *)[tableView dequeueReusableCellWithIdentifier:columnIdfer];
    if ( cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"StudentCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    

    if (indexPath.row < [self.MasterRecords count])
    {

        cell.iRecordIndex = indexPath.row;
    }
    
    
    return cell;
    
}

In the above code I set the iRecordIndex to IndexPath.row

StudentCell.h

@interface StudentCell : UITableViewCell
@property NSInteger iRecordIndex;
@property (weak, nonatomic) IBOutlet UIButton *btnSubmit;  // It pushes viewController.
@end

StudentCell.m

- (IBAction)btnSubmitPressed:(id)sender {
  
     NextViewController *sVC = [[NextViewController alloc]     initWithRecIndex:@"NextViewController" bundle:nil Index:self.iRecordIndex];

  // Pushing NextViewController to NavigationViewController.
}

NextViewController.h

@interface NextViewController : UIViewController <MKMapViewDelegate>
- (id)initWithRecIndex:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  Index:(NSInteger )iRecIndex;
@property NSInteger iRecordIndex;
@end

NextViewController.m

 - (id)initWithRecIndex:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  Index:(NSInteger )iRecIndex
{
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.iRecordIndex = iRecIndex;
    }

    return self;
}





-(void) viewWillAppear:(BOOL)animated
{
    //Get FistViewController.   say  ==> fvc.

    NSMutableArray *mRec = [fvc MasterRecords];
    NSMutableDictionary *mDict = [mRec objectAtIndex:self.iRecordIndex];
    
    NSLog (@" value1 is %@ ", [mDict valueForKey:@"value1"]);
    NSLog (@" value2 is %@ ", [mDict valueForKey:@"value2"]);
    
   // Using value1, and value2 to display MKMapView.


    
}

I am afraid if it is a right approach?. or where i could improve it?