什么是上传NSMutableArray数据到TableView的代码?

我已经parsing了通过Web服务传来的数据,并将这些数据存储到NSMutableArray.I想要显示这些全部数据到TableView中。 怎么可能?

正如你所说的,你已经收集了数据(NSMutableArray)中的数据。 您可以在TableView中显示这些数据为此,您必须按照以下步骤操作

1)在.h类中创buildUItableView的实例

AS UITableView *myTableView; 

2)在ViewController中采用UITableViewDataSource,UITableViewDelegate协议如果你要显示TableView

3)创build表(以编程方式或通过IB(界面生成器)在这里我以编程方式显示

 //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]; 

}

数据源方法在表视图中创build节数


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

数据源方法创build一个表视图的行数部分

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

数据源方法在表视图中创build单元格

  -(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; } 

我希望它会真的帮助你。

基本上你必须做一个UITableView(你可以在网上find一个教程),然后加载到它的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;