我的问题是,当点击单元格时,是否可以从 php 获取文本数据并在我的 ViewController 中读取它?
我猜didSelectRowAtIndexPath
是这样做的关键,但我不知道如何写。
我能够从 php 获取数据到我TableViewController
的如下;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [json count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSDictionary *info = [json objectAtIndex:indexPath.row];
cell.textLabel.text = [info objectForKey:@"Artist"];
cell.detailTextLabel.text = [info objectForKey:@"Song"];
return cell;
}