【问题标题】:What is code for upload the NSMutableArray data to TableView? [closed]将 NSMutableArray 数据上传到 TableView 的代码是什么? [关闭]
【发布时间】:2012-02-29 03:40:25
【问题描述】:

我已经解析了来自 Web 服务的数据,并将这些数据存储到 NSMutableArray 中。我想将这些整个数据显示到 TableView 中。 怎么可能?

【问题讨论】:

  • 以可读的方式提问。
  • @laxmanperamalla 你得到我的答案了吗,我解释了一切..

标签: iphone ios


【解决方案1】:

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

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

AS UITableView *myTableView;

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

3)创建表(以编程方式或通过 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];

}

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


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

希望对你有帮助。

【讨论】:

  • 创建表格视图确实是一个很好的解释。它包含在项目中创建表所需的一切。谢谢 !! @Kamarshad
【解决方案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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多