Manipulating UITableView... please help.

Discussion in 'iOS Programming' started by Abrexas, Jan 5, 2012.

  1. Abrexas macrumors member

    Joined:
    Jul 29, 2011
    #1
    Hey guys,
    Again, I have done quite a bit go research on this before coming here to ask, and if this is a repost then I sincerely apologize.

    So far what I have is a TableView that is filled with strings from an NSMutable array. That part works flawlessly. What I need to be done can be done in a few ways, and at this point i don't even care how it works out anymore.

    So here's the problem. Sometimes, the string in the array is longer than the phone is wide (even landscape). And as of now I am getting the typical '...' ending my string saying that there is more to be read.
    Now is there a way that I can implement a scroll view inside of each cell? (note that the array is mutable, and the user can simply add to it so I would be unable to manually put in a set number of scroll views)
    Another acceptable solution would be to have it so that when I click on one of the strings in the TableView, it pops up in a TextField that I could manually edit, save or delete in. (I can figure out the editing stuff on my own.) The thing is, I don't know how to use the string in the Table View as a button, or at least that is how i would imagine it to be .
    Also I have often seen a button in the cell's themselves that could be set to deleting the cell. How is this implemented?

    So if there are any other suggested methods about doing this, or if someone could point me in the right direction I would greatly appreciate it! I have been working on this app for a very long time and this is one of the last things I have to do before it is done.

    Thanks in advance!!
    - Steven French
     
  2. Abrexas thread starter macrumors member

    Joined:
    Jul 29, 2011
    #2
    okay I think I might have figured something out, but I am stuck on one part of my solution.

    I tried making a custom cell class and drawing up the label there. This worked, but I would like to link a Scroll View inside the Cell, but I don't have an xib. file for this class.

    What do I do?

    Thanks!
    - Steven French
     
  3. seepel macrumors 6502

    seepel

    Joined:
    Dec 22, 2009
    #3
    What is the end goal? Just to be able to see all the text? You can change the line break mode of the label, then you can also set variable cell heights from the table view delegate. Just use the sizeWithFont messages from the UIKit Category on NSString. Alternatively you could set the label to change the font size so the text fits (Assuming of course that the strings won't be too long to ever fit.

    If you want the text to be editable then you'll have to just stick a UITextField in the cell's contentView. On that note you can treat a cell's contentView just like any other view and put whatever you want in there (like a scrol
    View)
     
  4. Abrexas thread starter macrumors member

    Joined:
    Jul 29, 2011
    #4
    Putting a scroll view in the tableview would be optimal, but I can't figure out how that would be done. I tried making a custom cell class, but I don't know how to link it to a .xib and set up the scrollview and everything.

    To answer your question, the text can be too long to ever fit, so I need it to scroll, or just display somewhere else that I can implement scroll to. I know how to use scroll views outside of the tableview, so that isn't a problem.

    I don't want the text to take up more than one line. The content of the string wouldn't look right that way.

    So pretty much what I need is either some help putting a scroll view inside of the TableView, or learn how to do something along the lines of clicking on one of the cells, and having the full text appear somewhere else. I don't know how to make clicking one of the cells act as a button. Especially if I'm not making a custom cell.

    This is just all confusing for me haha. Thanks for responding though!
    - Steven French
     
  5. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #5
    Having the cell respond to taps requires adding putting code in tableView:didSelectRow: or something like that in your UITableViewDelegate. I might be off on the exact name, I'm not at a computer right now.
     
  6. jonnymo5 macrumors 6502

    Joined:
    Jan 21, 2008
    Location:
    Texas
    #6
    Are you sure you want to have so much text in a tablecell that you say will be too big to expand? You should consider launching another view when the user taps on the cell.

    How many lines are we talking? If it is less than 10 or so you can have the cells dynamically resize. If it could be hundreds then poping up another view with a nice big textview would be much easier for the user.

    You want to implement this method to detect they touched a row
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    Browse the Apple documentation on UITableViewDelegate to see all your options.
     
  7. seepel macrumors 6502

    seepel

    Joined:
    Dec 22, 2009
    #7
    I agree it seems best to just have the text span multiple lines. But putting a UIScrollView in a UITableView cell is pretty straight forward (kind of). Setup your scrollView, then add it to the table view. I would just do it programatically unless you are using a static UITableView in Story Board. I never liked monkeying around with UITableViewCells in IB. The only problem is that in the past if I wanted dynamically sized rows, and I put scroll views in them they didn't always behave nicely. Never did figure out what was going wrong.

    Code:
    [cell.contentView addSubview:scrollView];
    
     
  8. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    UITextView is a scroll view that displays text. Think that might help?
     

Share This Page