2012-12-17 106 views
0

我有一個plist字典和每個字典的字符串數量顯示在下面的URL。這個項目列表是plist中的成千上萬。顯示Plist數據到UItableview

我需要顯示這些數據的plist到的UITableView

eneter image

如何做到這一點?

我的代碼:

- (void)viewWillAppear:(BOOL)animated 
{ 
    // get paths from root direcory 
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                   NSUserDomainMask, YES); 
    NSString *documentsDirectory = [documentPaths objectAtIndex:0]; 
    NSString *documentPlistPath = [documentsDirectory stringByAppendingPathComponent:@"p.plist"]; 

    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:documentPlistPath]; 

    valueArray = [dict objectForKey:@"title"]; 

    self.mySections=[valueArray copy]; 
    NSLog(@"value array %@",self.mySections); 

} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return [self.mySections count]; 
} 

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 

    NSString *key = [[self.mySections objectAtIndex:section]objectForKey:@"pass"]; 
    return [NSString stringWithFormat:@"%@", key]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [self.mySections count]; 
} 

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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
    } 

    // Configure the cell... 
    NSUInteger section = [indexPath section]; 
    NSUInteger row = [indexPath row]; 

    cell.textLabel.text = [[self.mySections objectAtIndex:row] objectForKey:@"title"]; 
    cell.detailTextLabel.text=[[self.mySections objectAtIndex:section] objectForKey:[allKeys objectAtIndex:1]]; 

    return cell; 
} 
+0

可能重複的[Plist到UItableview](http://stackoverflow.com/questions/13926898/plist-into-uitableview) –

+0

@NickBull重複已經關閉作爲這個騙局... – Jack

回答

1

您已經運行了你的數組的末尾。

這可能是因爲你已經硬編碼每個部分的行數爲5.除非每個部分中確實有5行,否則應該在這裏返回一個動態值。

+0

雅感謝...輸出現在正在...但不是以適當的形式... plz check rowAtIndexPAth – Christien

+0

我如何知道您如何期望您的數據出來? – Abizern

+0

好的...部分應顯示@「通行證」,並在此行應顯示所有的字典值,包括通過 – Christien