2014-08-29 82 views
-3

i have multiple table view on a same view how to solve this error 如何解決這些錯誤的多個視圖

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


    if (tableView == method) { 
     static NSString *CellIdentifier = @"Cell"; 
     UITableViewCell *methodcell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if(methodcell == nil){ 
      methodcell = [[UITableViewCell alloc]initWithStyle:UITableViewStylePlain reuseIdentifier:CellIdentifier]; 
     } 
     methodcell.textLabel.text = [methodarray objectAtIndex:indexPath.row]; 
     return methodcell; 

    } 

    else if (tableView == schedule){ 

     static NSString *CellIdentifier = @"Cell"; 
     UITableViewCell *schedulecell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if(schedulecell == nil){ 
      schedulecell = [[UITableViewCell alloc]initWithStyle:UITableViewStylePlain reuseIdentifier:CellIdentifier]; 
     } 
     schedulecell.textLabel.text = [ScheduleArray objectAtIndex:indexPath.row]; 
     return schedulecell; 
    } 


} 
+1

這是我見過的最糟糕的錯誤描述,請詳細說明。 – 2014-08-29 06:55:04

+0

由於未返回單元而導致錯誤。在方法的末尾添加'return nil'並且錯誤將消失,但是請注意,如果這些if語句沒有通過您的應用程序將會崩潰。 – sbarow 2014-08-29 06:56:11

+0

謝謝sbarow。 – 2014-08-29 07:00:28

回答

1

可以deque的細胞如果要是外面{}其他{},其配置根據的tableView並返回。

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if(cell == nil){ 
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewStylePlain 
           reuseIdentifier:CellIdentifier]; 
} 
if (tableView == method) { 
    //configure cell for method tableView 
} else if (tableView == schedule) { 
    //configure cell for schedule tableView 
} 
return cell; 
2

的問題是,你的函數沒有返回任何東西的可能性。例如,如果您的ifelse if語句都返回FALSE,那麼您的函數將不會返回任何內容。此功能要求你返回的東西,所以你有幾個選項(完全依賴於你想要完成的任務):

  1. 您可以將函數的最後一個支架(這將返回如果沒有小區前加return nil;沒有if分公司執行)
  2. 你可以改變你的最後else ifelse,所以它執行,如果if回報FALSE
  3. 您可以添加其他else分支到您的if聲明

總之,你需要返回東西該函數調用結束。