06-13-2011, 03:29 PM
#1 (permalink )
Registered Member
Join Date: May 2011
Posts: 35
Assigning unique ID to a cell ref / disclosure button
Hi All,
I have a view controller (from a UITableView disclosure button) that jumps to another view controller (detail view) using the following code;
Code:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
addUS *editRecord = [[addUS alloc] init];
editRecord.editID = @"1";
[self presentModalViewController: editRecord animated:YES];
}
What I want to do give the editRecord.editID a unique value, for example I have a uid no that represents the record in the cell, I need to determine the record being clicked on and then passing that over to the editID property.
Cheers
Carl
06-13-2011, 04:20 PM
#2 (permalink )
Senior Member
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
Well, that's why that method is passed an NSIndexPath. Just like cellForRowAtIndexPath, where you say "OK, for that indexPath, I'm going to use this record".
So do whatever you do in cellForRowAtIndexPath to determine your record. Look it up in an array, or ask your NSFectchedResultsController for it, or however you do it in your app.
06-13-2011, 04:28 PM
#3 (permalink )
Registered Member
Join Date: May 2011
Posts: 35
Cell index - change to UID?
Hi,
Code:
cellForRowAtIndexPath
Isn't that the cell index? Is there an option to give it a uid other than the one generated based on order?
06-13-2011, 04:31 PM
#4 (permalink )
Senior Member
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
Yes, cellForRowAtIndexPath is passed the cell index.
Just like accessoryButtonTappedForRowWithIndexPath is passed the cell index.
Same cell index; same logic.
06-13-2011, 04:44 PM
#5 (permalink )
Registered Member
Join Date: May 2011
Posts: 35
Quote:
Originally Posted by
dljeffery
Yes, cellForRowAtIndexPath is passed the cell index.
Just like accessoryButtonTappedForRowWithIndexPath is passed the cell index.
Same cell index; same logic.
:-) got you. OK, so I have an array of data (being populated from JSON), how would I change the method to take whatever value I needed instead of the indexpath?
06-13-2011, 04:51 PM
#6 (permalink )
Senior Member
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
Depends; can you post your cellForRowAtIndexPath method?
06-13-2011, 04:56 PM
#7 (permalink )
Registered Member
Join Date: May 2011
Posts: 35
Quote:
Originally Posted by
dljeffery
Depends; can you post your cellForRowAtIndexPath method?
This is a mock cellForRowAtIndexPath method;
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
NSString *contentForThisRow = [[self contentsList] objectAtIndex:[indexPath row]];
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
[[cell textLabel] setText:contentForThisRow];
NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__);
return cell;
}
06-13-2011, 04:58 PM
#8 (permalink )
Senior Member
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
A mock one? As in, not your real implementation? In that case, it doesn't help.
But in this mock case, do exactly this same logic in accessoryButtonTappedForRowWithIndexPath to get your record:
Code:
NSString *contentForThisRow = [[self contentsList] objectAtIndex:[indexPath row]];
06-14-2011, 12:49 AM
#9 (permalink )
Registered Member
Join Date: May 2011
Posts: 35
Quote:
Originally Posted by
dljeffery
A mock one? As in, not your real implementation? In that case, it doesn't help.
But in this mock case, do exactly this same logic in accessoryButtonTappedForRowWithIndexPath to get your record:
Code:
NSString *contentForThisRow = [[self contentsList] objectAtIndex:[indexPath row]];
Thanks, that was exactly what I was after, works a treat.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80