2013-08-12 51 views
2

我不知道這個問題是否有問題,但我仍然在尋找答案。我在tableview概念中工作,並且創建了一個類似於一些菜單的收件箱,發送,設置etc.Now我想要的是我想創建子菜單的內部每個菜單,例如,如果我單擊收件箱它應該顯示新的,回覆,刪除等這樣的每個主菜單我想創建子菜單。使用數組,我們可以加載通過檢查部分,但沒有使用數組我想直接創建和着名的一個我已經使用自定義單元格我也想顯示圖像按菜單,如果它是收件箱我必須顯示收件箱圖像。任何人都可以幫助我嗎?如何在ios中的表格視圖中添加子菜單

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 8; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 8; 

} 

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *[email protected]"ViewProfileCell"; 

    MyHomeViewCell *cell= [[MyHomeViewCell alloc] init]; 

    cell=(MyHomeViewCell*)[tableView dequeueReusableCellWithIdentifier:cellidentifier]; 

    if(!cell) 
    { 
NSArray *nibofMyHomeCell=[[NSBundle mainBundle]loadNibNamed:@"MyHomeViewCell" owner:self options:Nil]; 
     cell=[nibofMyHomeCell objectAtIndex:0]; 


    } 

    if(indexPath.section==0) 
    { 
     [email protected]"Inbox"; 
    } 



} 

回答

0

有很多方法可以做到這一點。例如,您可以將每個項目顯示爲區域標題,並且如果輕觸區域標題,則顯示(或隱藏)該區域中的所有行。這些行是「子菜單」項目(新建,回覆,刪除)。或者您可以爲每個部分使用不同的部分以及如何或隱藏部分。或者顯示並隱藏行。這幾乎都是通過更改節和行數來控制的。

1

如你所說的收件箱,發,設置等

後,您需要創建另一個UITableView的其中將包含如新的子菜單按鈕或標籤,您可以創建一個UITableView其中將包含在它的細胞,回覆,刪除當點擊收件箱時。

Simillarly你會爲你的主UITableView中的其他單元做些什麼。

不要混淆我如何識別哪個tableview會被調用。

您將檢查的tableview名象下面這樣:

if(tableView==main) 
    { 
    ///Code for main menu tableview. 
    } 
    else if(tableView==sub) 
    { 
    ////Code for submenu tableview. 
    } 

這個你將在所有的UITableView委託和數據源的方法做:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
+0

期望創建新的tableview不能用自定義單元格嗎? –

+0

創建新的tableView將在本地更容易,而不是處理自定義單元格以及您想要創建自定義單元格的內容? –

相關問題