2012-08-22 93 views
0

我已經創建了一個自定義UITableViewCell,作爲子視圖添加到我的視圖。在這個視圖中還有一個UITableView。自定義UITableViewCell不屬於(包含)到UITableView設置自定義UITableViewCell選擇器

我已經在我的viewDidLoad方法中設置了自定義UITableViewCell像這樣。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Create custom tableviewCell at top of screen under navigation controller 

    cellContainer = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)]; 
    cellContainer.backgroundColor = [UIColor whiteColor]; 

    UITableViewCell *mycell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 50.0)]; 
    mycell.textLabel.text = @"Select all"; 
    mycell.backgroundColor = [UIColor whiteColor]; 


    [cellContainer addSubview:mycell]; 
    [self.view insertSubview:cellContainer atIndex:1]; 

    // Set table positioning 
    [subModelTableView setFrame:CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height - 44)]; 
    [self.view insertSubview:subModelTableView atIndex:0]; 

    // set tableview datasource and delegate 
    [subModelTableView setDelegate:self]; 
    [subModelTableView setDataSource:self]; 
} 

是在我無法選擇這個定製的tableview細胞瞬間的事情,我試圖在像這樣

[mycell addTarget:self action:@selector(myAwesomeMethod:) forControlEvents:UIControlEventTouchUpInside]; 

設置一個選擇,但我得到一個錯誤

No visible @interface for 'UITableViewCell' declares the selector 'addTarget:action:forControlEvents:' 

所以,我想知道是否有另一種方式做到這一點(正確的方式),或者如果我在正確的軌道上,我該如何解決這個錯誤?

編輯: 我之所以在此視圖中有這樣的額外UITableViewCell是,它坐在UINavigationBar下面,使用@靜態細胞「全選」在裏面,這種細胞坐在UITableView以上,但給被列入appeance在UITableView但顯然不是。

當用戶滾動值的UITableView如果用戶不知道他想要選擇哪個單元我想啓用@「全選」單元,所以他收到一個值的列表,將代表選擇每個單元格在UITableView。我希望這是有道理的。

+0

試試[mycell.contentView addTarget ...] – CSmith

+0

仍然給我一個錯誤,甚至把那個錯誤是不同的,但還是一樣.. **無可見@interface用於清洗後的項目'UIView'聲明瞭選擇器'addTarget:action:forControlEvents:'** – HurkNburkS

+0

是的,addTarget是一個UIControl類的方法,所以你只能在UIControl的視圖後代(比如UIButton)上做到這一點。你需要看看處理原始觸摸事件... – CSmith

回答

0

所以我想知道是否有這樣做 (有道)的任一種方式,或者如果我在正確的軌道上我怎樣才能解決這個 錯誤?

我不認爲這是做到這一點的正確方法。我認爲你應該使用UITableViewDelegate的didSelectRowAtIndexPath方法。如果這不起作用,那麼請詳細說明您要做什麼,以便提供更好的建議。

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

+0

是的我想使用UITableViewDelegates但是它們已被使用也是在這個視圖中的tableview。請檢查我編輯的問題,以瞭解我正在嘗試執行的操作。 – HurkNburkS

+0

是否有理由在一個視圖中需要多個TableView? – Brian

+0

我在底部添加了一個我想要實現的內容的編輯。因爲如果用戶找不到他們希望選擇的內容,他們可以選擇@「select all」 – HurkNburkS