dimanche 30 novembre 2014

how to pass data to next view on button click using collection view in iphone

Right now I am working with coredata and collection. I have an entity in coredta named "Employee" and it has multiple attributes(emp_id,name,address,dept). I am done with saving the data and successfully fetching the data. The thing is that I am using collection view and I am using delegate method("cellForItemAtIndexPath")of collection view and under this I am passing 'Employee'entity data from the coredata. I am setting the title of button by using the employee name(the no of buttons is equal to no of rows in coredata).


The problem starts here right now I want to perform an action on button click in that I want when I click a particular button I want to navigate to another controller and want to display all the information regarding that employee.I dont know how to do this I am pasting my code below.Your replies are mostly welcome:



- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
info = [array objectAtIndex:indexPath.row];
static NSString *cellIdentifier = @"empCell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
titlebutton = (UIButton *)[cell viewWithTag:100];
[titlebutton addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
[titlebutton setTitle:info.name forState:UIControlStateNormal];
return cell;
}


Here info is the instance of Employee entity. Buttons are displaying fine with their title as the name of employees in coredata. Here in this case I want to pass the id of each employee(say for button1 it is "1"..button2 it is "2") to another controller on button click. The prob is that the id which I m getting is for last button only because on run time the previous emp id is replaced by the last one. And here I am dealing with that particular prob i.e. how to pass each emp id to next controller on button click.




Aucun commentaire:

Enregistrer un commentaire