如何启动 UITableView



我正在使用 http://www.raywenderlich.com/的iReporter教程应用程序中的一些代码。

我在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 的结果放入表视图中。我想使用表格视图而不是滚动视图。

在数组中获取json数据。 使用objectForKey,然后使用以下 TablView 方法将该数据绑定到 tablview

并在 .h 中声明 tablview 委托和数据源,如下所示

.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;

}

试试这个代码....

最新更新