//
//  ttttViewController.h
//  tttt
//
//  Created by yjj on 11-5-24.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//#import <UIKit/UIKit.h>@interface ttttViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
    NSArray *nodelist;
    
}
@property (nonatomic, retain) NSArray *nodelist;@end
//
//  ttttViewController.m
//  tttt
//
//  Created by yjj on 11-5-24.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//#import "ttttViewController.h"@implementation ttttViewController
@synthesize nodelist;- (void)dealloc
{
    [super dealloc];
}- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}#pragma  - View lifecycle
#pragma TableViewDataSource Methods
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.nodelist count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * NoteScanIdentifier = @"NoteScanIdentifier";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NoteScanIdentifier];
    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NoteScanIdentifier];
    }
    NSUInteger row = [indexPath row];
    cell.textLabel.text = [nodelist objectAtIndex:row];
    return cell;
}/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/-(void)viewDidLoad
{
    NSArray *array = [[NSArray alloc]initWithObjects:@"2009-12-1",@"2009-12-2", @"2009-12-3",@"2009-12-4",@"2009-12-5",@"2009-12-6", nil];
    self.nodelist = array;
    [array release];
    [super viewDidLoad];
    
}- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}@end

解决方案 »

  1.   

    [tableView reloadData] 下看看
      

  2.   

    错了,你创建错文件了,你创建的是
    @interface ttttViewController : UIViewController,
    而UITableViewController应该是这样的
    @interface Conferencing : UITableViewController,
    如果你确实想在UIViewController中添加一个UITableView,则需要在代码上添加!
      

  3.   

    你创建文件的时候这样建会直接是个TableView
      

  4.   

    .....
    这个例子的确是在代码里写的一个tableview, 并将数据加载上的.
    没有错的. 
      

  5.   

    或者add一个table上去,并设着delegate和datesource为self
      

  6.   

    如果一个TableView加到UIView上面去,就得按8楼的方法去做,是没有问题的
      

  7.   

    感谢shulianyong, 这是一个例子, 我照着<<iphone应用程序指南>>上的一个实现一个简单的表的例子. 
    他的前提就是用View-based Application模板进行的. 
    并在.xib中拖入一个tableview. 然后连接file's owner两个接口. 然后写上程序. 但是写好了, 出现的是空白, 不知道是xcode4的原因, 还是什么.  
      

  8.   

    给你个实例
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 40, frame.size.width-20, 200) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    [tableView release];
      

  9.   

    非常感谢, 但是我还是想用例子上的方法来实现. 
    因为我在.xlb中已经添加了一个tableview. 是不是xcode3中就可以实现这个例子而在xcode4中应用别的做法还是什么?
      

  10.   

    因为你在引用ttttViewController时,是直接用的init,这样不能引用到你自定义的XIB,
    [[ttttViewController alloc] initWithNibName:@"ttttViewController" bundle:nil],这样的实例化才用引用到你自定义的XIB
      

  11.   

    这个不用管的, 在mainwindow视图里是自动加载的这个, 这个在创建时就已经建上了的. 
      

  12.   

    我刚才调试了一下你的代码, 应该不是代码的问题, 我用你的代码做个demo,显示没问题. 
    可能是你使用xib文件的方式出错 就这个问题 有这么几点需要在xib中处理  1. File's Owner与View要连接上, 按Ctrl连2.table的dataSource和delegate两个属性也要连接上File's Owner
    其他的应该就没什么了
      

  13.   


    我用的是xcode4.可能是这个原因吗?
      

  14.   

    灰常感谢大家, 经[小辉_西安<[email protected]>]在线指导, 是我将table_view将file's owner连接了, 导致的错误, 程序本身没有问题. 
    结贴.