2016-11-05 58 views
-1

我對Objective C非常陌生,現在我正在開發一個項目。View Controller中的每個單元格的視圖控制器

I've created a Slide-Out-Menu, which is based on my own Database

現在我想從每個Cell到ViewController中獲取一鍵組合舞蹈,但我還沒有真正的想法是如何工作的。

這裏是我的代碼

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
NSArray *numarray = [self getServerConnection]; 
for (NSDictionary *diction in numarray) { 
    NSDictionary *menuID = [diction objectForKey:@"id"]; 
    NSString *num = [NSString stringWithFormat:@"%@",menuID]; 
    intnum = [num intValue]; 
} 
return intnum; } 


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

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

NSArray *namearray = [self getServerConnection]; 
for (NSDictionary *diction in namearray) { 
    name = [result valueForKey:@"name"]; 
    identifier = [menuArray valueForKey:@"identifier"]; 

    cell.textLabel.text = name [indexPath.row]; 

} 

return cell; } 
+1

嗨,您應該向我們提供您的問題描述,一些您不明白的代碼或除視頻鏈接外的其他代碼。 – DominicanCoder

回答

1

假設你有一個在側面菜單,下面的數據分配4個細胞。

  1. 首頁
  2. 簡介
  3. 設置
  4. 關於我們

每個屏幕都從當前視圖控制器與一個標識目的地視圖控制器塞格斯。

使用UITableView類的委託方法。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    if (indexPath.row == 0){ 
     [self performSegueWithIdentifier:@"ProfileScreenSegueIdentifier" sender:self]; 
    }else if(indexPath.row == 1){ 
     [self performSegueWithIdentifier:@"HomeScreenSegueIdentifier" sender:self]; 
    }// So one... 
} 

注意:請在您的每個屏幕之間創建push seg ... 示例。 在上面的例子中也有將主屏幕

  1. 從個人資料首頁
  2. 從設置爲首頁
  3. 從關於我們首頁
  4. 3種可能性

所以,你需要創建3從那些屏幕到具有相同的segue標識符的家。 所以在上面的例子中會有12個segues。

相關問題