2

我开始了一个选项卡式应用程序项目,在我的第一个视图中,我想获得一个填充列表,所以我声明了一个 NSArray,如下所示:

@interface agrospineFirstViewController : UIViewController <UITableViewDelegate     ,UITableViewDataSource>
{
NSArray  *JournalList;
}
@property (nonatomic,retain) NSArray *JournalList;
@end

我在 .m 上添加了以下内容:

[超级视图DidLoad];

//initialisation de la liste
JournalList = [NSArray arrayWithObjects:@"journal1",@"journal2",nil];


//initialisation du table View 
UITableView* tableView=[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]style:UITableViewStylePlain];


//population de la vue


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [JournalList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (cell == nil)

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];

// Configuration de la cellule

NSString *cellValue = [JournalList objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;

}

我也将表格列表放入视图中......但仍然在 numberOfRowsInSection 上显示错误,要求将“:”替换为“;” 有什么帮助建议可以改进吗?

感谢您的时间

4

2 回答 2

2

我认为您还没有像这样关闭viewDidLoad方法:

- (void)viewDidLoad {
  [super viewDidLoad];

  //initialisation de la liste
  JournalList = [NSArray arrayWithObjects:@"journal1",@"journal2",nil];


  //initialisation du table View 
  UITableView* tableView=[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]style:UITableViewStylePlain];


  //population de la vue
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [JournalList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *MyIdentifier = @"MyIdentifier";

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

  if (cell == nil)

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];

  // Configuration de la cellule

  NSString *cellValue = [JournalList objectAtIndex:indexPath.row];
  cell.textLabel.text = cellValue;
  return cell;

}
于 2012-04-12T09:45:06.033 回答
2

你不需要这个
UITableView* tableView=[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]style:UITableViewStylePlain];

只需将表添加到 viewController 并像这样在 appDelegate 类上添加该 viewController 名称

UIViewController *homeViewController = [[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:homeViewController,nil];

只需在 xib 类中提供 delagate 和数据源连接

于 2012-04-12T10:14:40.367 回答