Custom UITableViewCell: Recognizing which cell to update

Hello,
I have created a custom UITableViewCell in IB with two UIButtons and one UILabel. What I would like to do is have each button perform an action on the UILabel - lets just say change the UILabel's text for now. I have the following set up and everything works.
MyViewController.m/h
_ Has UITableViewCell property and IBOutlet connected to MyCustomTableCell
_ Has two IBAction methods to handle each UIButton pressed
MyCustomTableCell
_ File Owner set to MyViewController
_ Has tags denoting each item
_ UIButtons events are connected to the custom methods in MyViewController.m
Just as a test, I have populated 3 rows in the table. When I hit either UIButton from any row, it only updates the last row's UILabel text. The method that handles the UIButton's event is something like:
-(IBAction)buttonOnePressed:(id)sender
UILabel *myLabel = (UILabel*) [customLoadedCell viewWithTag:1];
myLabel.text = @"button one";
How do I recognize which row the button's event came from so I can only update that label?

sptrakesh wrote:
The button that triggered the event will be the child of the appropriate cell.
Took me awhile but I finally understood what you meant. So basically what I did inside the method to handle the touch up event was:
UITableViewCell *mycell = (UITableViewCell *)[[sender superview] superview];
UILabel *myLabel = (UILabel*) [mycell viewWithTag:4];
myLabel = @"test";
The first line allows to get a reference to the UITableViewCell I tapped. If I needed the row number I could reference it by doing this:
NSIndexPath *ip = [self.tableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
ip.row will return the row number.
self.tableView is the reference to the table view.

Similar Messages

  • I have had my apple tv 2 for about 3 months which work perfectly fine when I use it with my iPad 3 ー all of the sudden I get the HDCP Error!  I read the forms and done everything!  Apple I name a loyal customer, please come out with an update soon!

    I have had my apple tv 2 for about 3 months which work perfectly fine when I use it with my iPad 3 ー all of the sudden I get the HDCP Error!  I read the forms and done everything!  Apple I name a loyal customer, please come out with an update soon!

    That's one of the weird things.. it recognizes it maybe 10% of the time. And usually, only after I do the two-button reset. Problem is.. since it won't charge above 2%, anytime I try to do a restore or anything like that using iTunes, my device shuts off and I lose whatever progress I'd made.
    So, an update... after reading through a bunch of similar complaints (there are literally 1000's of them so there's NO WAY this isn't somehow ios7 related, thanks a lot APPLE ) I decided to try a restore in recovery mode. After 3 hours and several disconnections... I ended up having to just set it up as a new iPad, as the restore did nothing. Weirdly though... as I was doing the restore in recovery mode.. I noticed I'd gotten up to a 10% charge.. higher than it's been since September, so after setting it up as a new device, I turned it off and plugged it in using the wall charger. 2 hours later and I was up to 38%. Still not great, as my iPad, before ios7 could've fully charged twice in the amount of time it took for me to now get 28% more of a charge. And that's with a fully cleaned out device.. so that really ***** and I'm now more confused than ever.
    But I'm gonna leave it overnight charging and see what I come up with tomorrow. Sadly, when I paid $600 for it in February, I never expected to have to play "wait and see" with it...

  • How to edit label in custom UITableViewCell?

    Hi, I'm a newby in iPhone programming, I have created a custom UITableViewCell with 3 labels and I have populated an UITableView with some rows. I need to change the text of one of the labels when the user select the cell.
    I wrote this:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *theCellSelected = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    theCellSelected = [theTableView cellForRowAtIndexPath:indexPath.row];
    UILabel *theLabelToEdit = (UILabel *)[theCellSelected viewWithTag:1];
    theLabelToEdit.text = @"Some Text..";
    ..but nothing happen to the label, the text doesn't change..
    What's wrong?
    Thank you!
    PS: sorry for my english, I'm italian and I don't speak it very well..

    Hi Zoodany, and welcome to the Dev Forum!
    zoodany wrote:
    I wrote this:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    theTableView = tableView;
    // remove --> static NSString *CellIdentifier = @"Cell";
    UITableViewCell *theCellSelected;
    // remove --> = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    theCellSelected = [theTableView cellForRowAtIndexPath:indexPath]; // <-- remove '.row'
    UILabel *theLabelToEdit = (UILabel *)[theCellSelected viewWithTag:1];
    theLabelToEdit.text = @"Some Text..";
    Assuming your @interface, xib and DataSource methods are consistent with the above, the only thing stopping your code from working would be the 'indexPath.row' arg as commented. The lines which dequeue a cell won't prevent your code from running, though if any cells are actually in the queue, you'll have a memory leak there.
    However, I doubt the code you posted is the same as the code you tested. If you actually coded cellForRowAtIndexPath:indexPath.row, you should have gotten a warning since 'row' is an int instead of a pointer. And if you had ignored that warning the program would have crashed at that line. This kind of mixup often happens when the programmer keys code into the forum instead of pasting it directly from the source file. Please copy and paste when posting your code here (also see the alert about formatting code, the first topic of the forum), ok?
    If indeed 'indexPath.row' is a red herring, I think we need to look elsewhere in your project for the problem.
    I have created a custom UITableViewCell
    This contradicts your code somewhat. If you subclassed UITableViewCell, you'd normally add ivars with matching @properties to the custom cell so you could access the subviews as cell.label1, cell.label2, etc. Using viewWithTag to find one of the labels suggests that you simply added the labels to vanilla UITableViewCell objects rather that subclassing (adding the labels without subclassing is probably the best choice if no further customization is required).
    So please let us know whether or not you actually defined a subclass of UITableViewCell. Assuming you didn't, here's an example of how to add labels to your cells (only two labels are added below to simplify the example):
    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
    reuseIdentifier:CellIdentifier] autorelease];
    // make label 1
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 3, 140, 38)];
    label.text = @"Label 1";
    label.backgroundColor = [UIColor lightGrayColor];
    label.font = [UIFont boldSystemFontOfSize:20];
    label.tag = 1;
    [cell.contentView addSubview:label];
    [label release];
    // make label 2
    label = [[UILabel alloc] initWithFrame:CGRectMake(160, 3, 140, 38)];
    label.text = @"Label 2";
    label.backgroundColor = [UIColor yellowColor];
    label.font = [UIFont boldSystemFontOfSize:20];
    label.tag = 2;
    [cell.contentView addSubview:label];
    [label release];
    // Set up the cell...
    return cell;
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *theCellSelected = [tableView cellForRowAtIndexPath:indexPath];
    UILabel *theLabelToEdit = (UILabel *)[theCellSelected viewWithTag:1];
    theLabelToEdit.text = @"Some Text..";
    Note that 'tableView' is used in the delegate method instead of an instance variable such as 'theTableView'. The 'tableView' parameter will always be set to the address of the table view which is calling the delegate method, so there's no need to use an ivar in this case. In fact, 'theTableView' could also be the cause of your problem. For example if you made the table view in IB, you might have forgotten to connect the 'theTableView' outlet of the controller (or File's Owner) to the UITableView object. So you might also check that connection, though the code above doesn't depend on it.
    Hope that helps!
    - Ray

  • Is there a recommended limit on the number of custom sections and the cells per table so that there are no performance issues with the UI?

    Is there a recommended limit on the number of custom sections and the cells per table so that there are no performance issues with the UI?

    Thanks Kelly,
    The answers would be the following:
    1200 cells per custom section (NEW COUNT), and up to 30 custom sections per spec.
    Assuming all will be populated, and this would apply to all final material specs in the system which could be ~25% of all material specs.
    The cells will be numeric, free text, drop downs, and some calculated numeric.
    Are we reaching the limits for UI performance?
    Thanks

  • Instantiating a custom UITableViewCell from IB

    What is the recommended way to instantiate a custom UITableViewCell, or other object, created in IB that your app may need multiple instances of?
    My current approach is something along the following lines:
    NSArray *topLevelObjs = [[NSBundle mainBundle] loadNibNamed:@"CustomViewCell" owner:self options:nil];
    cell = [topLevelObjs objectAtIndex:1];
    This works, but doesn't seem particularly elegant. I tried implementing NSCopying for the custom class at one point but there doesn't seem to be any easy way to deep copy the class instance.
    Any suggestions?

    Digging through the apple example apps I found an example in "NavBar". An example of the relevant code:
    UIViewController *customViewController = [[CustomViewController alloc] initWithNibName:@"CustomViewController" bundle:nil];
    Message was edited by: dreyruugr

  • Custom Toolbar from Macro is not updating when Macro is updated

    I have a Word template 2010 (.dotm) that has a macro that originated at least 2007, if not earlier.  There is a Customized Toolbar with Drop downs in the Add-ins tab populated from the Macro that contains a list of names. The drop down values have stopped
    updating as additional names have been added.  I can get the individual names to appear in the QAT but that is not what we need. How do I get the Drop Downs in Customized Toolbar to update so that the new names appear under the drop down as specified
    in the macro?  This is a snip it from the macro
    Drop down is US
    Name in Drop Down is Sales1
    Sub USSales1()
    ' USSales1 Macro
    ' Macro recorded 2/5/2007 by Myerse00
        Selection.TypeText Text:="Sales Region 1"
        Selection.MoveRight Unit:=wdCell
        Selection.TypeText Text:="149 Branch"
        Selection.TypeParagraph
        Selection.TypeText Text:="CA"
        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
        Selection.TypeText Text:="805"
        Selection.TypeParagraph
        Selection.TypeText Text:="805"
        Selection.TypeParagraph
        Selection.TypeText Text:="Please email"
    End Sub
    Any suggestions would be very much appreciated.
    N-

    Easily customizable toolbars were a feature of Word 97-2003 that corporate IT departments complained about. MS eliminated them, giving us the QAT instead. Such a toolbar never would have been automatically updated.
    You can modify your toolbar using Word 2003. Otherwise, you can learn to do it using vba. I've never had the patience.
    You can create custom ribbon tabs which are both more powerful and useful using XML (not through the Word 2010 program directly).
    Customize the Ribbon (It doesn't take rocket science)
    You may also want to explore the use of AutoText and Building Blocks.
    Automated Boilerplate Using Microsoft Word With the AutoTextList field these could perhaps replace your macros without learning a lot of programming.
    AutoTextList field - How to add pop-up lists to any Word document, so you can click your way through changes in seconds
    Charles Kenyon Madison, WI

  • How do I add URI web link with custom tooltip like "CLICK HERE TO UPDATE" instead of URI web link in tooltip.

    How do I add URI web link with custom tooltip like "CLICK HERE TO UPDATE" instead of URI web link in tooltip.

    You've probably found an answer to this by now, but I think this has been addressed in another forum -- The link below suggested using a button and adding the tooltip to the button. 
    https://forums.adobe.com/thread/304974?start=0&tstart=0
    Sounds like it would work but I haven't actually tried it. 
    Good luck~!

  • I am trying to use a website that requires that my computer have the lastest version of Java, which I have updated and installed, however Firefox does not recon

    I am trying to use a website that requires that my computer have the latest version of Java, which I have updated and installed Java 7 Update 51 (64-bit), however Firefox does not recognize that I even have Java on my computer. My computer is 64-bit
    When I run "Verify Java Version" it show nothing is installed... but it is, I know that for a fact because it shows in my "Control Panel/Programs/Programs and Features".
    When I go back to the Java Download page, the following message is visible:
    "We have detected you may be viewing this page in a 32-bit browser. If you use 32-bit and 64-bit browsers interchangeably, you will need to install both 32-bit and 64-bit Java in order to have the Java plug-in for both browsers."
    My question is this:
    Is there a way to change my Firefox browser from 32-bit to 64-bit.... because it appears that this is way Java is not functioning properly?

    Firefox needs 32-bit plugins, so you'll need to install 32-bit Java for Firefox.
    No, you can't change Firefox from 32-bt to 64-bit. There is a Nightly 64-bit version (alpha) of Firefox, but it is used only to test for regressions until development is resumed.

  • I have a Windows 8 laptop which has been updated to 8.1. I'm trying to rename a playlist and it won't let me do it - it did last time but I've updated my itunes since then. What's happened and how can I do it, please.

    I have a Windows 8 laptop which has been updated to 8.1. I'm trying to rename a new playlist in my itunes which I could change befor the last update which was very recent. It won't do it like it used to. Help, please! reetz58

    yeah it is the gayest thing that happens :S what i do is turn off the internet, then open it, then turn on internet, then use it. :S OR make your homepage a tab.

  • Table component - how to find out which cell is clicked

    Hello!
    I have a couple of questions regarding table component
    1. Is there any way to find out which table cell is clicked on?
    2. And is it possible to paint clicked cell programmatically?
    Possible solution might be a Select Boolean Checkbox inside a cell, but anyway, i'd have to determine which cell contains this checkbox (some kind of cell coordinates, etc...)
    Thank you

    1. Is there any way to find out which table cell is clicked on? It would be easy to suggest the way, if you can share us the requirement
    2. And is it possible to paint clicked cell programmatically?You can do it through javascript by setting contentStyle property.
    Sample Code:
    <af:table ...>
      <af:column>
         <af:inputText ...>
                  <af:clientListener method="paintCurrentCell" type="click"/>
         </af:inputText>
      </af:column>
    </af:table>
    <!-- javascript method -->
    function paintCurrentCell(event){
        event.getSource().setContentStyle("background-color:red");
      }Sireesha
    Edited by: Sireesha Pinninti on Nov 10, 2009 7:01 PM

  • Why isn't my Ipod nano 6th generation being recognized on itunes after updating software to 1.2

    Why isn't my Ipod nano 6th generation being recognized on itunes after updating software to 1.2?

    I found that all the movies that I want on my nano have iTunes extras.

  • I upgraded my 3 yr old iMac to Snow Leopard and now my HP C4150 Scanning function doesn't work (not recognized).  I downloaded updated Drivers from the HP site, but still no joy.  Any suggestions?

    I upgraded my 3 yr old iMac to Snow Leopard (OS X 10.6) and now my HP C4150 Scanning function doesn't work (not recognized).  I downloaded updated Drivers from the HP site and installed them, but still no joy.  Any suggestions?

    aspaceman,
    Perhaps I owe you an apology.   Having re-read that downloading from HP was unsuccessful I feel uncomfortable.  Can I suggest you update your 10.6 system (as noted in your profile) to 10.6.8 (if it is not already there) by using the
    Mac OS X 10.6.8 Update Combo v1.1 combo update plus any software updates that then apply.  

  • TS1702 I use iphone5, I see an app update on the app store. but when App store and click on the update tab, it doesn't show me which application to update.. just give me a blank page.!!!! what is the solution for this.!!!!

    I use iphone5, I see an app update on the app store. but when App store and click on the update tab, it doesn't show me which application to update.. just gives me a blank page.!!!! I wouldn't able to know what app has to be updated, untill and unless i get check for each every app on the app store installed on my iphone... what is the solution for this.!!!! can any1 one help me out.!!!!

    Cc2528 wrote:
    The iTunes Store on my iPad is set up with all my music already. And at the very bottom it shows my apple Id username. The only place it shows the previous owners id is in the App Store...
    You can probably change the ID in the "iTunes and App stores" settings on the iPad....click on the wrong account ID , select sign out, then log in with your own ID, I have not done this but I think it works.....
    but I would be more inclined to to the factory reset and start afresh.

  • I have an Iphone 4 which I just updated with the latest software, which put in it in Recovery Mode. It has the picture of the plug with Itunes, I downloaded it now its saying its in Recovery Mode, how do I save all of my previous data without Restoring?

    I have an IPhone 4 which I just updated with the latest software, which put in it in Recovery Mode. It has the picture of the plug with ITunes, I downloaded it now its saying its in Recovery Mode, how do I save all of my previous data without Restoring?
    I updated the phone before backing it up on iTunes, now the update wanted me to connect the phone with iTunes and it says the phones in recovery mode and it must be restored before its used with iTunes. I go to click restore and it says it will reset it to factory default and I'll lose all my current data. I have all my sons pictures and videos along with this notes. I can't lose all of this data! Please help!

    You have to restore the iPod, no ifs, ands, or buts...
    After iOS is installed you will be asked if you what to set it up as a new iPod or if you want to restore from a backup.
    If you have a good backup you can restore that and you're good to go.
    If you don't have a good backup, then you end up with a "clean" iPod....

  • When payment is made to Vendor for an open line item. Which table's updated

    Hi,
    When an invoice has been posted for a GR. The invoice will be pending for  payment. And when the payment is made to the vendor .Which table is updated, as i need to create a functional spec for triggering a message automatically to initate vendor payment if it is due for a month. I want the table name?
    Regards
    Chandan

    Hi,
    The payment document posted is again a accounting document, the table is BKPF - Header and BSEG - Item.
    In order to know if a LIV accounting document is cleared i.e payment made could be checked in the field
    BSEG-REBZG. this field would carry the payment document number, which is again a accounting document ( table bkpf-bseg).
    hope this helps.
    Harish

Maybe you are looking for

  • Color mismatch Windows 8.1 and Acrobat X and XI Pro

    I am creating a PDF from Excel 2013 using both Acrobat X and Acrobat XI on my ASUS laptop running Windows 8.1.  Text that is blue in Excel 2013 looks purple both in the PDF and when viewing the uploaded PDF in Internet Explorer.  The text in the PDF

  • Which harddrive/backup drive for my iMac

    I have a 20" aluminum iMac, about 1 year old, running Leopard. I the the internal HD has capacity for about 250GB if memory serves me right. I have about 200GB of stuff on it now, most of which is pictures in iphoto, music, and videos. Was thinking I

  • Is there a way to merge paths?

    I drew several paths with the pen tool, overlapping at various points.  Is there a way to take the union of these paths?

  • My contacts did not reappeared after I updated my iPhone's 4 to iOS 6

    I did not back up the phone before I decided to update the software to ios6?! So after updating the software on my iPhone and re starting the phone, I was very upset to go through my phone and not have any of my contacts. I was able to recover all em

  • Upgrade to Premiere Elements 8.0?

    I recently purchased Photoshop Elements 8.0.  It had a 30 day trial version bundled with it for Premiere Elements 8.0 which I installed.  I have used it enough to now want to upgrade (as offered for I believe $49.95) but can find no way to do this fr