2013-10-23 37 views
0

我正在使用来自http://www.raywenderlich.com/的iReporter教程应用程序的一些代码。如何启动UITableView

我得到这个代码在StreamScreen.m:

-(void)refreshStream { 
    //just call the "stream" command from the web API 
    [[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"stream", @"command", nil] onCompletion:^(NSDictionary *json) { 
     //got stream 
     [self showStream:[json objectForKey:@"result"]]; 
    }]; 
} 

我怎样才能把结果从JSON成的tableview。我想使用tableview而不是scrollview。

+0

看看我写回信呃.... – Jitendra

+0

@ user2908800考虑到你的问题实际上是关于[JSON](https://en.wikipedia.org/wiki/JSON),你应该更仔细地标题和标记。 –

回答

0

获取您的json数据。使用objectForKey,然后使用以下方法tablview

数据结合成tablview和声明tablview代表且dataSource在.H这样

.H文件

<UITableViewDelegate,UITableViewDataSource> 

.m文件把这个代码

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 

      return 1; 

     } 

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 

      return [stream count]; 


     } 

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


      AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate]; 

      static NSString *CellIdentifier = @"Cell"; 
      cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
      if (cell == nil) 
      { 
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

      } 
      cell.textLabel.text=[stream objectAtIndex:indexPath.row]; 
      return cell; 


} 

试试这个代码....