Zouhair
Zouhair

Reputation: 31

implementing UITableView sections from an NSDictionary objects

I want to use an NSDictionary to populate a table view. Are there any tutorials to show me how this is done.

Upvotes: 1

Views: 541

Answers (1)

jigneshbrahmkhatri
jigneshbrahmkhatri

Reputation: 3637

Need to check what contains inside NSDictionary, Here, I assume that there would be NSString as values inside Main NSDictionary, here is code for that

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tV{
return 1;
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{
return [dictMain count];
}

- (UITableViewCell *)tableView:(UITableView *)tV cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (cell==nil) {
    cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier] autorelease];
}
NSString *value = [dicMain objectForKey:[[dicMain allKeys] objectAtIndex:indexPath.row]];
cell.textLabel.text = value;
return cell;
}

Upvotes: 2

Related Questions