Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sakthivadivel.a

macrumors newbie
Original poster
Oct 31, 2011
13
0
chennai - -India
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
 
Last edited by a moderator:
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


How do you know numbers has actually loaded data?
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.