读书人

UITableView菜鸟使用方法!

发布时间: 2012-05-02 15:36:04 作者: rapoo

UITableView初学者使用方法!急急急!!!!
a.h文件的代码如下:

#import <UIKit/UIKit.h>

@interface tableviewtest : UIView
{
UITableView *DataTable;


}
@property (nonatomic, retain) IBOutlet UITableView *DataTable;

@end


a.m文件的代码如下:
#import "a.h"
@implementation tableviewtest
@synthesize DataTable;

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code

}

return self;
}


- (void)layoutSubviews {

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// There is only one section.
return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of time zone names.
return 3;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *MyIdentifier = @"MyIdentifier";

// Try to retrieve from the table view a now-unused cell with the given identifier.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

// If no cell is available, create a new one using the given identifier.
if (cell == nil) {
// Use the default cell style.
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
//cell.imageView.image=image;//未选cell时的图片
//cell.imageView.highlightedImage=highlightImage;//选中cell后的图片
// Set up the cell.
//NSString *timeZoneName = [timeZoneNames objectAtIndex:indexPath.row];
cell.textLabel.text = @"test";
return cell;

}

@end


问题是现在不知如何在TABLEVIEW中添加数据,请教请教!!!!!

[解决办法]
[tableview reloadData];

读书人网 >Iphone

热点推荐