我已经解析了通过Web服务传来的数据,并将这些数据存储到NSMutableArray中。我想将这些整体数据显示在TableView中。 怎么可能?上传NSMutableArray数据到TableView的代码是什么?
-1
A
回答
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
相关问题
- 1. 从代理传递NSMutableArray到tableview
- 2. Tableview的代码如何上传NSMutableArray项目?
- 3. 如何将解析的数据上传到tableview的代码?
- 4. 如何将NSMutableArray数据项拖到tableview?
- 5. nsmutablearray到tableview
- 6. 上传到Screeps的代码的许可证是什么?
- 7. asp代码上传数据
- 8. 数据上传到错误的节点。代码中出现了什么问题?
- 9. 为什么这个TableView代码有效?
- 10. 为什么当地的Jekyll代码与上传到github的代码不同?
- 11. 什么是在amazon s3 api上传文件的coldfusion代码?
- 12. 什么是S3对象上传到数据库
- 13. 什么是文件添加数据并上传到REST API
- 14. 将1,600,000行数据上传到mysql数据库的最佳方式是什么?
- 15. 什么是从一个NSMutableArray
- 16. Qt的 - 什么是代码
- 17. 从的tableView将数据传递到另一个的tableView
- 18. 什么是必要的项目到文档上的代码?
- 19. 什么是从JavaScript到C#代码
- 20. 传递数据到tableView单元格swift
- 21. 什么是tableview数据源中的cell.textLabel.text行的实际意义?
- 22. 这是什么意思“的数据。名称?”下面的代码
- 23. NSMutableArray到NSString到UIImageView代码破解
- 24. NSMutableArray。 Objective-C的到SWIFT代码
- 25. 什么是WordPress短代码?代码中的代码有什么区别?
- 26. 为什么我在代码中的out参数上得到代码分析CA1062?
- 27. 数据库或代码?为什么?
- 28. 的NSMutableArray +的tableView + SQLite的
- 29. 什么是由意向返回的结果代码或数据
- 30. excel宏vba - 填充数据的代码是什么?
以可读的方式提问。 – 2012-02-29 05:01:25
@laxmanperamalla你有没有得到我的答案,我解释了一切.. – Kamarshad 2012-02-29 06:04:46