//
// 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 mark - View lifecycle
#pragma markTableViewDataSource 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] 下看看
|
|
在哪里写, 或做呢? |
|
| 1分 |
错了,你创建错文件了,你创建的是
@interface ttttViewController : UIViewController, 而UITableViewController应该是这样的 @interface Conferencing : UITableViewController, 如果你确实想在UIViewController中添加一个UITableView,则需要在代码上添加! |
| 1分 |
你创建文件的时候这样建会直接是个TableView
![]() |
|
….. |
|
| 2分 |
或者add一个table上去,并设着delegate和datesource为self
|
| 2分 |
如果一个TableView加到UIView上面去,就得按8楼的方法去做,是没有问题的
|
|
感谢shulianyong, 这是一个例子, 我照着<<iphone应用程序指南>>上的一个实现一个简单的表的例子.
他的前提就是用View-based Application模板进行的. 并在.xib中拖入一个tableview. 然后连接file””s owner两个接口. 然后写上程序. 但是写好了, 出现的是空白, 不知道是xcode4的原因, 还是什么.
|
|
| 5分 |
给你个实例
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]; |
|
非常感谢, 但是我还是想用例子上的方法来实现. |
|
| 3分 |
因为你在引用ttttViewController时,是直接用的init,这样不能引用到你自定义的XIB,
[[ttttViewController alloc] initWithNibName:@”ttttViewController” bundle:nil],这样的实例化才用引用到你自定义的XIB |
![]() 这是截屏 |
|
|
这个不用管的, 在mainwindow视图里是自动加载的这个, 这个在创建时就已经建上了的. |
|
| 5分 |
我刚才调试了一下你的代码, 应该不是代码的问题, 我用你的代码做个demo,显示没问题.
可能是你使用xib文件的方式出错 就这个问题 有这么几点需要在xib中处理 1. File””s Owner与View要连接上, 按Ctrl连 2.table的dataSource和delegate两个属性也要连接上File””s Owner 其他的应该就没什么了 |
|
我用的是xcode4.可能是这个原因吗? |
|
|
灰常感谢大家, 经[小辉_西安<ghosthkfly@gmail.com>]在线指导, 是我将table_view将file””s owner连接了, 导致的错误, 程序本身没有问题.
结贴. |
|

