2012-05-29 53 views
0

IM上的應用程序,具有搜索視圖中工作, 搜索視圖包含的tableView與3個部分 - i。由如何確定在UITableView的小區中的區段 - 目標c

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 3; 
} 


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ 

    if (section == 0){ 
     UITextField *title = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 320, 10)]; 
     [title setBackgroundColor:[UIColor lightGrayColor]]; 
     [title setTextAlignment:UITextAlignmentRight]; 
     [title setFont:[UIFont boldSystemFontOfSize:15]]; 
     [title setText:@"videos"]; 
     return title ; 
    } 
    if (section == 1){ 
     UITextField *title = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 320, 10)]; 
     [title setBackgroundColor:[UIColor lightGrayColor]]; 
     [title setTextAlignment:UITextAlignmentRight]; 
     [title setFont:[UIFont boldSystemFontOfSize:15]]; 
     [title setText:@"documents"]; 
     return title ; 
    } 
    if (section == 2){ 
     UITextField *title = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 320, 10)]; 
     [title setBackgroundColor:[UIColor lightGrayColor]]; 
     [title setTextAlignment:UITextAlignmentRight]; 
     [title setFont:[UIFont boldSystemFontOfSize:15]]; 
     [title setText:@"questions"]; 
     return title ; 
    } 
} 

現在手動執行部與接收到的XML看起來像這樣我的所有數據:

<?xml version="1.0" encoding="utf-8"?> 
<rss version="2.0"> 
<channel> 
    <title>documents</title> 
     <item> 
     <title>how to count the days</title> 
     <link>some link...</link> 
     <date>11/09/2007 16:45:00</date> 
     <SupplierName>roei</SupplierName> 
     <CategoryName>the omer</CategoryName> 

     </item> 

     <item> 
     <title>research</title> 
     <link>some link...</link> 
     <date>16/05/2010 13:41:00</date> 
     <SupplierName>eran</SupplierName> 
     <CategoryName>shavoot</CategoryName> 
     </item> 

</channel> 

<channel> 
    <title> video </title> 
       <item> 
       <title>the end of holiday</title> 
       <link>some link...</link> 
       <date>06/06/2011 08:56:00</date> 
       <SupplierName>dina</SupplierName> 
       <CategoryName>shavoot</CategoryName> 

       </item> 

       <item> 
       <title>bible</title> 
       <link>some link...</link> 
       <date>24/05/2012 10:00:00</date> 
       <SupplierName>amir</SupplierName> 
       <CategoryName>shavoot</CategoryName>   
       </item> 

</channel> 



     <channel> 
      <title>questions</title> 

       <item> 
       <title>questions for shavvot</title> 
       <link>some link...</link> 
       <date>28/10/2008 13:31:00</date> 
       <SenderName>אלי.ד.</SenderName> 
       <CategoryName>holidays</CategoryName> 
       </item> 

       <item> 
       <title>Shavoot</title> 
       <link>some link...</link> 
       <date>25/05/2008 01:01:00</date> 
       <SenderName>amir</SenderName> 
       <CategoryName>holidays</CategoryName> 
       </item> 


     </channel> 


</rss> 

,你可以見式我與段的名稱頭銜,但我應該如何確定,細胞的正確部分? IM解析所有的數據到一個數組,然後得到它使用字典:

NSDictionary *object = [ResultsArrayDisplay objectAtIndex:indexPath.row]; 

請幫我而言,我什麼也沒有幫助的在互聯網上迄今嘗試的幾個小時後。

回答

0

這是你的問題:

IM中的所有數據解析到一個數組,然後得到它使用 詞典:

把數據每一部分在自己的數組,然後使用indexPath.section來確定使用哪個數組。對於每個部分,它只會爲您提供的行,因此您可以使用indexPath.row來索引您的每個陣列。

如果你堅持把所有東西放在一個數組中,那麼你將不得不保持每種類型的數量,然後用它來確定你需要的數組索引。

無論哪種情況,請務必執行numberOfRowsinSection:。如果你使用多個數組,那麼這將只是該部分的數組數,否則它將成爲該部分中使用的主數組的一部分。

+0

好吧,即時通訊工作..我會讓你知道,如果我需要任何幫助。 TNX –

+0

我終於做到了,謝謝你我的朋友,你幫了很多! –