Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-13-2011, 03:29 PM   #1 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 35
scrumsolutions is on a distinguished road
Question 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
scrumsolutions is offline   Reply With Quote
Old 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
dljeffery is on a distinguished road
Default

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.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 06-13-2011, 04:28 PM   #3 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 35
scrumsolutions is on a distinguished road
Default 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?
scrumsolutions is offline   Reply With Quote
Old 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
dljeffery is on a distinguished road
Default

Yes, cellForRowAtIndexPath is passed the cell index.

Just like accessoryButtonTappedForRowWithIndexPath is passed the cell index.

Same cell index; same logic.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 06-13-2011, 04:44 PM   #5 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 35
scrumsolutions is on a distinguished road
Wink

Quote:
Originally Posted by dljeffery View Post
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?
scrumsolutions is offline   Reply With Quote
Old 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
dljeffery is on a distinguished road
Default

Depends; can you post your cellForRowAtIndexPath method?
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 06-13-2011, 04:56 PM   #7 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 35
scrumsolutions is on a distinguished road
Default

Quote:
Originally Posted by dljeffery View Post
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;
}
scrumsolutions is offline   Reply With Quote
Old 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
dljeffery is on a distinguished road
Default

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]];
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 06-14-2011, 12:49 AM   #9 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 35
scrumsolutions is on a distinguished road
Smile

Quote:
Originally Posted by dljeffery View Post
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.
scrumsolutions is offline   Reply With Quote
Reply

Bookmarks

Tags
cell reference, uitableview, unique id

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 313
6 members and 307 guests
chemistry, Dnnake, iOS.Lover, lendo, Leslie80, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:23 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0