//
// 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
@interface ttttViewController : UIViewController,
而UITableViewController应该是这样的
@interface Conferencing : UITableViewController,
如果你确实想在UIViewController中添加一个UITableView,则需要在代码上添加!
这个例子的确是在代码里写的一个tableview, 并将数据加载上的.
没有错的.
他的前提就是用View-based Application模板进行的.
并在.xib中拖入一个tableview. 然后连接file's owner两个接口. 然后写上程序. 但是写好了, 出现的是空白, 不知道是xcode4的原因, 还是什么.
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];
因为我在.xlb中已经添加了一个tableview. 是不是xcode3中就可以实现这个例子而在xcode4中应用别的做法还是什么?
[[ttttViewController alloc] initWithNibName:@"ttttViewController" bundle:nil],这样的实例化才用引用到你自定义的XIB
可能是你使用xib文件的方式出错 就这个问题 有这么几点需要在xib中处理 1. File's Owner与View要连接上, 按Ctrl连2.table的dataSource和delegate两个属性也要连接上File's Owner
其他的应该就没什么了
我用的是xcode4.可能是这个原因吗?
结贴.