1

So I have a popup table view that displays 3 names. What I am trying to get is when a user selects a name from the popup table it will close the popup and display that name on a label or textfield on the original view controller. Here is what I have so far:

(selectedName is the name of the label I have on the original viewcontroller)

- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; selectedName.text = cell.textLabel.text; } 

Its not working and I am also looking for a way for the popup to disappear when a cell is clicked. Any ideas?

EDIT: (code for setting cell label text)

cell.textLabel.text = [[myArray objectAtIndex:indexPath.row] objectForKey:@"Name"]; 
8
  • 1
    Why obvious? What you have seems sensible. Do you ever set a value to cell.textLabel when you create it? It looks to me like what you are missing is actually displaying the name. You appear to be setting it to an iVar properly. Also, show the code that you use to present your popup. Noone knows how you are doing this; therefore, noone could possibly know how you could dismiss it. Commented Feb 8, 2013 at 18:45
  • How is this popup displayed? Is it a modal view? Is it a popover view? Is it some strange custom alert view? Commented Feb 8, 2013 at 18:48
  • Yes its set to read a value from an array. It displays correctly on the table cells. I just meant obviously its not working thats why I am here. That is what is confusing me because it should be working. Commented Feb 8, 2013 at 18:48
  • Lets see, you are storing the the selected text. Good. Where is your code that sets the label or textfield? Commented Feb 8, 2013 at 18:50
  • @DanF its a popover view and its a separate viewcontroller. I just have it ctr+draged from the button to the popover view. Would that effect it? Commented Feb 8, 2013 at 18:50

1 Answer 1

1

What you can do is to define a protocol that your tableview can use to communicate to the presenter. This is a common practice.

Here is a crude example:

@protocol MyTableViewDelegate<NSObject> -(void)myTableView:(TheTableViewClass *)tableView didSelectValue:(NSString *)value; @end @interface TheTableViewClass : UITableViewController @property (nonatomic, assign) id<MyTableViewDelegate> d; @end @implementation TheTableViewClass @synthesize d; - (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; [self.d myTableView:self didSelectValue:cell.textLabel.text]; } @end @implementation MyPresenter -(void)present { self.myTableViewClass = [MyTableViewClass ....]; self.myTableViewClass.d = self; //present myTableViewClass... } -(void)myTableView:(TheTableViewClass *)tableView didSelectValue:(NSString *)value { //Set some label to the value passed in //Dismiss self.myTablViewClass } @end 

Some additional reading: Working with Protocols

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.