在代码下方,列表正确显示,因此设置了出口和协议方法(委托,数据源)。
方法 tableview:didSelectRowAtIndexPath: 它打印出 (null) 而不是列表中的正确元素
//
// MainViewController.m
// ProvaTable
//
// Created by Alessandro on 12/6/12.
// Copyright (c) 2012 Alessandro. All rights reserved.
//
#import "MainViewController.h"
@interface MainViewController ()
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) NSArray *listOfObjects;
@end
@implementation MainViewController
@synthesize tableView = _tableView;
@synthesize listOfObjects = _listOfObjects;
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.listOfObjects = [NSArray arrayWithObjects:@"Object 1",@"Object 2", nil];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.listOfObjects count];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell Item";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
}
// Set up the cell...
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
cell.textLabel.text = [self.listOfObjects objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@",[self.listOfObjects objectAtIndex:indexPath.row]);
}
@结尾