将NSMutableArray数据上传到TableView的代码是什么? [英] What is code for upload the NSMutableArray data to TableView?

查看:103
本文介绍了将NSMutableArray数据上传到TableView的代码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经解析了通过Web服务传输的数据,并且已将这些数据存储到NSMutableArray中。我想将这些整数数据显示在TableView中。
怎么可能?

I have parsed the data coming through the web services and I have stored these data into NSMutableArray.I want to show these Whole Data in to TableView. How it is possible?

推荐答案

你告诉过你已经收集了数组中的数据(NSMutableArray)。
您可以在TableView中显示这些数据为此您必须遵循以下步骤

AS you told you have collected the data in your Array(NSMutableArray). You can show these data in TableView For this you have to follow below Steps

1)在.h类中创建UItableView的实例

1)Create Instance of UItableView in .h class

AS UITableView *myTableView;

2)在ViewController中采用UITableViewDataSource,UITableViewDelegate协议你要在哪里展示TableView

2) Adopt The UITableViewDataSource,UITableViewDelegate protocol in ViewController Where you going to show TableView

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

3)Create Table (programmatically or by IB(Interface Builder) here i am showing Programmatically

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



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



Data Source method to create number of rows section of a Table View

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



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



Data Source method to create cells in Table View

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

我希望它真的能帮到你。

I Hope It'll really Help You .

这篇关于将NSMutableArray数据上传到TableView的代码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆