How to populate UITableView with plist

后端 未结 1 1751
醉梦人生
醉梦人生 2020-12-22 03:43

I have a simple UITableView that I\'d like to populate using a plist file. I have followed a few tutorials but they all seem to over complicate the process and in the end I

相关标签:
1条回答
  • 2020-12-22 04:27

    To load the file :

    thearray = [NSArray arrayWithContentsOfFile:thePath];
    

    Then you need to set your controller as the data source and delegate for the table view and implement at least :

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
         return 1;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {    
        return [thearray count];
    }
    
    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell* cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
    
        // assuming your array contains only simple strings :
        cell.textLabel.text = [thearray objectAtIndex:indexPath.row];
    
        return cell;
    }
    

    This doesn't use the "reuse" of cells which is important if your list is big.

    0 讨论(0)
提交回复
热议问题