【问题标题】:how to load data to tableviewcontroller via web webservice?如何通过 web 服务将数据加载到 tableviewcontroller?
【发布时间】:2013-12-09 13:11:51
【问题描述】:

我有一个UITableViewCotroller,它将从NSArray(RestaurantsArray) 获取数据, 这个餐厅数组是通过使用一个调用 Web 服务并使用返回的 JSON 的对象来实现的。 这是我试图在UITableViewCotroller 中填充数组的地方:

- (void)viewDidLoad
 {
    [super viewDidLoad];
    RestaurantsList* tempObject=[[RestaurantsList alloc]init];

    RestaurantsArray=[[NSMutableArray alloc]init];

    RestaurantsArray=[tempObject loadTheRestaurantList];  

 }

但问题是请求操作在 tableviewcontroller 结束加载之前不会触发,因此RestaurantsArray 保持为空。

我想要的是调用 Web 服务,结束消费操作,然后填充数组,该数组将成为 tableview 的数据源

【问题讨论】:

  • [tableview reloaddata];从 webservice 获取数据后重新加载表
  • 我试过这个,但操作正在重复,因为我是第一次加载视图顺便说一下,在我确保数组已经被覆盖之后,是否有覆盖“重新加载表”的兼容性填满
  • 我想很明显我使用的是 tableviewcotroller 而不是 tableview
  • 第一次视图加载,然后在 viewdidload 方法中将 tableview delgate 设置为 nil 后得到 websrvice 的响应 set tableview delegate self 并重新加载 tableview 明白了吗?
  • @Rushabh 我不明白你的想法,请你解释一下

标签: ios iphone objective-c web-services ios6


【解决方案1】:

什么是 loadTheRestaurantList 方法? 如果你使用 NSURLConnection 加载数据,有一个 NSURLConnectionDelegate,它有方法

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 

在您的请求完成并加载完成后调用此方法。在此方法中,您可以通过 NSNotificationCenter 发布通知并在您的 UITableViewCotroller 中收听。

【讨论】:

    猜你喜欢
    • 2021-02-20
    • 2012-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多