.h
@interface Dialogue : UITableViewController
{
NSArray *choice;
}
@property (nonatomic, retain) NSArray *choice;
- (void) initChoices;
@end
.m Table View Cell的Identifier CellIdentifier 記得加
@synthesize choice;
- (void)viewDidLoad
{
[super viewDidLoad];
[self initChoices];
}
- (void) initChoices
{
NSDictionary *allChoice = [[NSDictionary alloc] initWithObjectsAndKeys:
@"All Choice", @"title",
@"content_allChoice", @"content", nil];
NSDictionary *myChoice = [[NSDictionary alloc] initWithObjectsAndKeys:
@"My Choice", @"title",
@"content_myChoice", @"content", nil];
choice = [[NSArray alloc] initWithObjects: allChoice, myChoice, nil];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [choice count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *each = [self.choice objectAtIndex: indexPath.row];
cell.textLabel.text = [each objectForKey: @"title"];
//cell.textLabel.text = [each objectForKey: @"content"];
return cell;
}
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。