2012-02-29 42 views

回答

2

基本上,你必须做出一个UITableView(你可以在网上找到一个教程),然后到NSMutableArray中加载到它,使用下面的代码的方法

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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    // Configure the cell... 
     cell.textLabel.text = [theArray objectAtIndex: indexPath.row]; 

    return cell; 
3

照你说你已经收集到的数组中的数据(NSMutableArray)。 您可以显示TableView中,这些数据对于这一点,你必须遵循以下步骤

1).H类

AS UITableView *myTableView; 

2)采用在视图控制器的UITableViewDataSource,的UITableViewDelegate协议创建的UITableView的实例你去哪儿显示的TableView

3)创建表(编程方式或通过IB(Interface Builder中) 我在这里显示编程

//you may call this Method View Loading Time.  
-(void)createTable{ 
myTableView=[[[UITableView alloc]initWithFrame:CGRectMake(0, 0,320,330) style:UITableViewStylePlain] autorelease]; 
myTableView.backgroundColor=[UIColor clearColor]; 
myTableView.delegate=self; 
myTableView.dataSource=self; 
myTableView.separatorStyle= UITableViewCellSeparatorStyleNone; 
myTableView.scrollEnabled=YES; 
[self.view addSubview:myTableView]; 

}

数据源的方法来创建表视图部分的数目


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
return 1; 
} 

数据源的方法来创建一个表视图

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

数据的行部分的数目在表视图中创建单元格的源方法

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

static NSString *CellIdentifier = @"Cell"; 
//here you check for PreCreated cell. 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

//Fill the cells... 
    cell.textLabel.text = [yourMutableArray objectAtIndex: indexPath.row]; 
//yourMutableArray is Array 
return cell; 
} 

我希望它会真的帮助你。

+0

这是真正的创建表视图的好解释。它包含在项目中创建表所需的所有内容。谢谢 !! @Kamarshad – 2012-02-29 16:22:13

相关问题