picking datas from plist file.

Discussion in 'iOS Programming' started by sakthivadivel.a, Nov 7, 2011.

  1. sakthivadivel.a, Nov 7, 2011
    Last edited by a moderator: Nov 7, 2011

    sakthivadivel.a macrumors newbie

    Joined:
    Oct 31, 2011
    Location:
    chennai - -India
    #1
    Hi all,

    I want to display the datas present in the plist file. I have written the code, but my code is not fetching the data from plist file. Here is my - code
    Code:
    (void)viewDidLoad {
    	
    	NSString *myFile = [[NSBundle mainBundle]pathForResource:@"breakdown" ofType:@"plist"];
    	numbers = [[NSArray alloc]initWithContentsOfFile:myFile];
           NSLog(@"%@",numbers);
    
    [SIZE="4"]//numbers is an array and breakdown is my plist file
    // My console file generates null value, but my plist file contains values[/SIZE]
            [super viewDidLoad];
    }
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 6;
    }
    
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    	if(section == 0) return 0;
    	if(section == 1) return 2;
    	if(section == 2) return 2;
    	if(section == 3) return 2;
    	if(section == 4) return 2;
    	if(section == 5) return 3;
    	return numbers.count; 
    }
    
    
    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
        static NSString *CellIdentifier = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
    	
    	int theRow = indexPath.row;
    	if(indexPath.section == 0)
    		
    	if(indexPath.section == 1)theRow += 2;
            if(indexPath.section == 2) theRow += 4;
            if(indexPath.section == 3) theRow += 6;
    	if(indexPath.section == 4) theRow += 8;
    	if(indexPath.section == 5) theRow += 11;
    	cell.textLabel.text = [numbers objectAtIndex:theRow];
            
        // Configure the cell...
        
        return cell;
    }
    
    If anyone knows where i did the mistake, kindly suggest me.

    Regards
    sakthi
     
  2. Sykte macrumors regular

    Joined:
    Aug 26, 2010
    #2

    How do you know numbers has actually loaded data?
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Are you sure breakdown.plist has been copied to your app's bundle (and not just linked to it).
     
  4. sakthivadivel.a thread starter macrumors newbie

    Joined:
    Oct 31, 2011
    Location:
    chennai - -India
    #4
    Working Fine

    Now it is working fine. The mistake i did was, i didn't change the root type to Array in my breakdown.plist file. By Default it was Dictionary, now changed to Array.

    Now it is working fine.


    Thanks.
     

Share This Page