2013-02-08 197 views
1

所以我有一個彈出表格視圖,顯示3個名稱。我試圖得到的是,當用戶從彈出表中選擇一個名稱時,它將關閉彈出窗口,並在原始視圖控制器的標籤或文本框上顯示該名稱。以下是我迄今爲止:從xcode中的單元格內的文本字段獲取值

(selectedName是標籤我對原來的ViewController的名字)它不工作

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



} 

,我也在尋找一種方式,在彈出消失當單元格被點擊時。有任何想法嗎?

編輯:(設置單元格標籤文本代碼)

cell.textLabel.text = [[myArray objectAtIndex:indexPath.row] objectForKey:@"Name"]; 
+1

爲什麼明擺着的嗎?你看起來很明智。當你創建它時,你有沒有爲cell.textLabel設置一個值?它在我看來像你缺少的是實際顯示的名稱。您似乎正確地將其設置爲iVar。另外,請顯示您用來顯示彈出窗口的代碼。沒有人知道你是如何做到這一點的;因此,沒有人可能知道你如何解僱它。 – Jeremy 2013-02-08 18:45:48

+0

如何顯示此彈出窗口?這是一種模態觀點嗎?這是一個popover視圖嗎?它是一些奇怪的自定義警報視圖? – 2013-02-08 18:48:06

+0

是的它設置爲從數組中讀取值。它在表格單元格上正確顯示。我只是表示它不工作,這就是爲什麼我在這裏。這就是讓我困惑的原因,因爲它應該起作用。 – bardockyo 2013-02-08 18:48:45

回答

1

你可以做的是定義你的tableview能傳達到演示者的協議。這是一種常見的做法。

這裏是一個最原始的例子:

@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 

一些額外閱讀:Working with Protocols

相關問題